Merge remote-tracking branch 'origin/main'

This commit is contained in:
Guille Gutierrez 2023-02-24 17:06:10 -05:00
commit 91fac0c3bd
3 changed files with 41 additions and 1 deletions

31
hub_api/buildings.py Normal file
View File

@ -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)

View File

@ -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):
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'

View File

@ -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)