api_v1.4/hub_api/buildings.py

31 lines
1004 B
Python

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)