mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Add method to count of live services and orgs
So that we don’t have to update the home page manually any more.
This commit is contained in:
@@ -6,6 +6,7 @@ from app.models import (
|
||||
Organisation,
|
||||
Domain,
|
||||
InvitedOrganisationUser,
|
||||
Service,
|
||||
User
|
||||
)
|
||||
|
||||
@@ -16,6 +17,14 @@ def dao_get_organisations():
|
||||
).all()
|
||||
|
||||
|
||||
def dao_count_organsations_with_live_services():
|
||||
return db.session.query(Organisation.id).join(Organisation.services).filter(
|
||||
Service.active.is_(True),
|
||||
Service.restricted.is_(False),
|
||||
Service.count_as_live.is_(True),
|
||||
).distinct().count()
|
||||
|
||||
|
||||
def dao_get_organisation_services(organisation_id):
|
||||
return Organisation.query.filter_by(
|
||||
id=organisation_id
|
||||
|
||||
@@ -61,6 +61,14 @@ def dao_fetch_all_services(only_active=False):
|
||||
return query.all()
|
||||
|
||||
|
||||
def dao_count_live_services():
|
||||
return Service.query.filter_by(
|
||||
active=True,
|
||||
restricted=False,
|
||||
count_as_live=True,
|
||||
).count()
|
||||
|
||||
|
||||
def dao_fetch_service_by_id(service_id, only_active=False):
|
||||
query = Service.query.filter_by(
|
||||
id=service_id
|
||||
|
||||
@@ -5,6 +5,8 @@ from flask import (
|
||||
)
|
||||
|
||||
from app import db, version
|
||||
from app.dao.services_dao import dao_count_live_services
|
||||
from app.dao.organisation_dao import dao_count_organsations_with_live_services
|
||||
|
||||
status = Blueprint('status', __name__)
|
||||
|
||||
@@ -23,6 +25,14 @@ def show_status():
|
||||
db_version=get_db_version()), 200
|
||||
|
||||
|
||||
@status.route('/_status/live-service-and-organisation-counts')
|
||||
def live_service_and_organisation_counts():
|
||||
return jsonify(
|
||||
organisations=dao_count_organsations_with_live_services(),
|
||||
services=dao_count_live_services(),
|
||||
), 200
|
||||
|
||||
|
||||
def get_db_version():
|
||||
query = 'SELECT version_num FROM alembic_version'
|
||||
full_name = db.session.execute(query).fetchone()[0]
|
||||
|
||||
Reference in New Issue
Block a user