Refactor:
Correct swagger definition. MEB uses body, so should be a post method not a get according to REST definition. active_session now refresh the session also if valid. partial implementation for meb.
This commit is contained in:
parent
fff40611d5
commit
80337a5cc5
|
@ -9,23 +9,23 @@ class Meb(Resource, Config):
|
|||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def get(self):
|
||||
def post(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, token, application_uuid)
|
||||
payload = request.get_json()
|
||||
buildings = {}
|
||||
|
||||
for city in payload['cities']:
|
||||
buildings[city] = {}
|
||||
for building in payload['cities'][city]:
|
||||
buildings[city][building] = self.export_db_factory.building_info(building, city)
|
||||
city_name = next(iter(city))
|
||||
buildings[city_name] = {}
|
||||
print(city[city_name])
|
||||
for building in city[city_name]:
|
||||
print(building)
|
||||
# buildings[city][building] = self.export_db_factory.building_info(building, city)
|
||||
|
||||
# TODO: finish formatting buildings to match swagger documentation
|
||||
# and change export_db_factory.building_info to use MEB database
|
||||
|
|
|
@ -38,7 +38,7 @@ class SessionStart(Resource, Config):
|
|||
'ip': ip,
|
||||
'cities': []
|
||||
}
|
||||
cities = self.export_db_factory.cities_by_user(user_info.id)
|
||||
cities = self.export_db_factory.cities_by_user_and_application(user_info.id, user_info.application_id)
|
||||
for city in cities:
|
||||
session['cities'].append({
|
||||
"name": city.name,
|
||||
|
|
|
@ -140,19 +140,22 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/unauthorized'
|
||||
/v1.4/buildings/meb:
|
||||
get:
|
||||
post:
|
||||
security:
|
||||
- session_id: [ ]
|
||||
- token: [ ]
|
||||
- application_uuid: [ ]
|
||||
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.
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
required:
|
||||
- cities
|
||||
properties:
|
||||
cities:
|
||||
type: object
|
||||
description: Cities list
|
||||
example: { "cities": [ { "city_1": [ "building_1", "building_2" ] }, { "city_2": [ "building_3", "building_8" ] } ] }
|
||||
tags:
|
||||
- Buildings monthly energy balance meb
|
||||
summary: Retrieve the monthly energy balance results for the given buildings in the given cities
|
||||
|
@ -227,8 +230,8 @@ components:
|
|||
type: string
|
||||
example: 'succeed'
|
||||
results:
|
||||
type: string
|
||||
example: '[
|
||||
type: object
|
||||
example: '{"results":[
|
||||
{
|
||||
"city_1":{
|
||||
"building_1":{
|
||||
|
@ -421,4 +424,4 @@ components:
|
|||
}
|
||||
}
|
||||
}
|
||||
]'
|
||||
]}'
|
|
@ -109,4 +109,7 @@ def refresh_session(session_id, token, application_uuid):
|
|||
|
||||
|
||||
def active_session(session_id, token, application_uuid):
|
||||
return _validate_session(session_id=session_id, token=token, application_uuid=application_uuid)
|
||||
_is_valid = _validate_session(session_id=session_id, token=token, application_uuid=application_uuid)
|
||||
if _is_valid:
|
||||
refresh_session(session_id, token, application_uuid)
|
||||
return _is_valid
|
||||
|
|
Loading…
Reference in New Issue
Block a user