From 54533fe0e33ad718a746e472b6098828e0c117c3 Mon Sep 17 00:00:00 2001 From: KoaCWells Date: Fri, 24 Feb 2023 16:57:51 -0500 Subject: [PATCH] Add skeleton for getting enriched buildings and Windows path fix --- hub_api/buildings.py | 31 +++++++++++++++++++++++++++++++ hub_api/config.py | 8 +++++++- hub_api/helpers/session_helper.py | 3 +++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 hub_api/buildings.py diff --git a/hub_api/buildings.py b/hub_api/buildings.py new file mode 100644 index 0000000..ab1d386 --- /dev/null +++ b/hub_api/buildings.py @@ -0,0 +1,31 @@ +import json +from flask import Response, request +from flask_restful import Resource + +from hub_api.helpers.session_helper import active_session, refresh_session +from hub_api.config import Config + +class GetBuildings(Resource, Config): + def __init__(self): + super().__init__() + + 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)): + refresh_session(session_id) + + building_ids = request.get_json() + buildings = self.export_db_factory.get_buildings_by_id(building_ids) + + if(bool(buildings)): + return(Response(json.dumps(buildings), status=200)) + + return Response(json.dumps({'result': 'buildings not found'}), status=204) + + return Response(json.dumps({'error': 'unauthorized'}), status=403) \ No newline at end of file diff --git a/hub_api/config.py b/hub_api/config.py index 90aa21c..4e7d0b3 100644 --- a/hub_api/config.py +++ b/hub_api/config.py @@ -5,6 +5,8 @@ Copyright © 2023 Project Peter Yefi peteryefi@gmail.com """ import pickle from pathlib import Path +import platform +import os from hub.city_model_structure.city import City from hub.exports.db_factory import DBFactory as CityExportFactory @@ -14,7 +16,11 @@ from hub.imports.db_factory import DBFactory class Config: def __init__(self): - dotenv_path = Path('/usr/local/etc/hub/.env').resolve() + if platform.system() == 'Linux': + dotenv_path = Path('/usr/local/etc/hub/.env').resolve() + elif platform.system() == 'Windows': + dotenv_path = "{}/.env".format(os.path.expanduser('~')) + environment = 'TEST' database_name = 'persistence_test' diff --git a/hub_api/helpers/session_helper.py b/hub_api/helpers/session_helper.py index b2a240b..844aaf5 100644 --- a/hub_api/helpers/session_helper.py +++ b/hub_api/helpers/session_helper.py @@ -97,3 +97,6 @@ def refresh_session(session_id, token, application_uuid): return sessions[session_id] return None + +def active_session(session_id, token, application_uuid): + return _validate_session(session_id = session_id, token = token, application_uuid = application_uuid) \ No newline at end of file