"""Handlers for internal endpoints. This module contains the request handlers for endpoints under the "/internal" sub-root of the application. These endpoints are designed to be inaccessible from external networks (i.e. they are not proxied or exposed by ows-grass). They can only be called from within the trusted private network. """ from owsresponse import response from owsresponse.adaptors.flask import flaskify from account.api import app from account.constants import error from account.models import parent_company as parent_company_model @app.route('/parent_companies', methods=['GET']) def get_parent_companies(): """Get list of parent companies.""" parent_companies = parent_company_model.get_parent_companies() return flaskify( response.Response({'parent_companies': [pc.to_dict() for pc in parent_companies]}) ) @app.route('/parent_companies/', methods=['GET']) def get_parent_company(parent_company_uuid): """Get a single parent company by UUID.""" pc = parent_company_model.get_parent_company(parent_company_uuid) if not pc: return flaskify( response.create_error_response( code=error.ERROR_CODE_NOT_FOUND, message='Parent company not found', status=404, ) ) return flaskify(response.Response(pc.to_dict())) @app.route('/parent_companies//companies', methods=['GET']) def get_parent_company_companies(parent_company_uuid): """Get a single parent company by UUID.""" pc = parent_company_model.get_parent_company_company_brands(parent_company_uuid) if not pc: return flaskify( response.create_error_response( code=error.ERROR_CODE_NOT_FOUND, message='Parent company not found', status=404, ) ) return flaskify( response.Response( { 'companies': [ { 'id': cb.id, 'name': cb.name, 'uuid': cb.uuid, 'display_name': cb.display_name, 'logo_url': cb.logo_url, } for cb in pc.company_brands ] } ) )