From fa06b571f8aec562b74042f8a181b92e212ddbea Mon Sep 17 00:00:00 2001 From: guille Date: Fri, 10 Mar 2023 10:15:20 -0500 Subject: [PATCH] Small adjustments for meb --- bootstrap.py | 6 ++-- hub_api/{buildings.py => buildings/meb.py} | 14 ++++---- hub_api/docs/openapi-specs.yml | 40 +++++----------------- 3 files changed, 19 insertions(+), 41 deletions(-) rename hub_api/{buildings.py => buildings/meb.py} (83%) diff --git a/bootstrap.py b/bootstrap.py index 230bbdf..6f4b4e0 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -17,7 +17,7 @@ import threading import hub_api.helpers.session_helper as sh from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive from hub_api.uptime import Uptime -from hub_api.buildings import GetMEB +from hub_api.buildings.meb import Meb sh.begin_time = datetime.datetime.now() @@ -33,7 +33,7 @@ api.add_resource(SessionEnd, '/v1.4/session/end') api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive') # Buildings -api.add_resource(GetMEB, '/v1.4/buildings/meb') +api.add_resource(Meb, '/v1.4/buildings/meb') with open("hub_api/docs/openapi-specs.yml", "r") as stream: swagger_config = { @@ -53,7 +53,7 @@ with open("hub_api/docs/openapi-specs.yml", "r") as stream: try: Swagger(app, template=yaml.safe_load(stream), config=swagger_config) except yaml.YAMLError as exc: - print(exc) + print(f'error: {exc}') @app.route("/") diff --git a/hub_api/buildings.py b/hub_api/buildings/meb.py similarity index 83% rename from hub_api/buildings.py rename to hub_api/buildings/meb.py index 207fb91..e08e3be 100644 --- a/hub_api/buildings.py +++ b/hub_api/buildings/meb.py @@ -5,19 +5,19 @@ from flask_restful import Resource from hub_api.helpers.session_helper import active_session, refresh_session from hub_api.config import Config -class GetMEB(Resource, Config): +class Meb(Resource, Config): def __init__(self): super().__init__() - def post(self): - ''' + def get(self): + """ API call for requesting a specified list of enriched buildings - ''' + """ session_id = request.headers.get('session_id', None) token = request.headers.get('token', None) application_uuid = request.headers.get('application_uuid', None) - if(active_session(session_id, token, application_uuid)): + if active_session(session_id, token, application_uuid): refresh_session(session_id, token, application_uuid) payload = request.get_json() buildings = {} @@ -27,9 +27,9 @@ class GetMEB(Resource, Config): for building in payload['cities'][city]: buildings[city][building] = self.export_db_factory.building_info(building, city) - #TODO: finish formating buildings to match swagger documentation + # TODO: finish formatting buildings to match swagger documentation # and change export_db_factory.building_info to use MEB database # call when ready return Response(json.dumps({'result': 'succeed', 'results': buildings}), status=200) - return Response(json.dumps({'error': 'unauthorized'}), status=403) \ No newline at end of file + return Response(json.dumps({'error': 'unauthorized'}), status=403) diff --git a/hub_api/docs/openapi-specs.yml b/hub_api/docs/openapi-specs.yml index ffcb848..055d223 100644 --- a/hub_api/docs/openapi-specs.yml +++ b/hub_api/docs/openapi-specs.yml @@ -140,28 +140,19 @@ paths: schema: $ref: '#/components/schemas/unauthorized' /v1.4/buildings/meb: - post: + get: security: - session_id: [ ] - token: [ ] - application_uuid: [ ] - requestBody: - content: - application/json: - schema: - type: object - properties: - cities: - type: object - example: {"city_1" :["building_1", "building_2"], "city_2" :["building_3", "building_8"]} - - # schema: - # ref: '#components/schemas/buildingsArray' - # payload: - # type: object - # example: {"city_1" :["building_1", "building_2"], "city_2" :["building_3", "building_8"]} - # required: true - # description: Json containing the city name and the buildings whose monthly energy balance is requested. + parameters: + - in: body + name: data + schema: + type: string + example: [{"city_1" :["building_1", "building_2"]}, {"city_2" :["building_3", "building_8"]}] + required: true + description: Json containing the city name and the buildings whose monthly energy balance is requested. tags: - Buildings monthly energy balance meb summary: Retrieve the monthly energy balance results for the given buildings in the given cities @@ -229,19 +220,6 @@ components: cities: type: array example: [{'name': 'city 1', 'geometric_level_of_detail': '1'}, {'name': 'city 2', 'geometric_level_of_detail': '1'}] - buildingsArray: - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/buildings' - buildings: - type: object - properties: - city_id: - type: string - example: 'city_id1' meb: type: object properties: