Redefine api structure
Add future methods Update documentation
This commit is contained in:
parent
01281e4b31
commit
ec90dd1e0d
@ -18,7 +18,7 @@ class Config:
|
||||
dotenv_path = Path('/home/guille/.local/etc/hub/.env').resolve()
|
||||
|
||||
environment = 'TEST'
|
||||
database_name = 'hub_unittests'
|
||||
database_name = 'montreal_retrofit_test'
|
||||
|
||||
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
|
||||
|
@ -22,9 +22,12 @@ class SessionStart(Resource, Config):
|
||||
def put(self):
|
||||
username = request.headers.get('username', None)
|
||||
password = request.headers.get('password', None)
|
||||
application_uuid = request.headers.get('application_uuid', None)
|
||||
try:
|
||||
application_uuid = uuid.UUID(request.headers.get('application-uuid', None))
|
||||
user_info = self.database.user_login(name=username, password=password, application_uuid=application_uuid)
|
||||
except ValueError:
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
ip = request.remote_addr
|
||||
user_info = self.export_db_factory.user_login(name=username, password=password, application_uuid=application_uuid)
|
||||
if user_info:
|
||||
session_id = str(uuid.uuid4())
|
||||
token = str(uuid.uuid4())
|
||||
@ -38,7 +41,7 @@ class SessionStart(Resource, Config):
|
||||
'ip': ip,
|
||||
'cities': []
|
||||
}
|
||||
cities = self.export_db_factory.cities_by_user_and_application(user_info.id, user_info.application_id)
|
||||
cities = self.database.cities_by_user_and_application(user_info.id, user_info.application_id)
|
||||
for city in cities:
|
||||
session['cities'].append({
|
||||
"name": city.name,
|
||||
@ -59,9 +62,9 @@ class SessionEnd(Resource):
|
||||
|
||||
@staticmethod
|
||||
def put():
|
||||
session_id = request.headers.get('session_id', None)
|
||||
session_id = request.headers.get('session-id', None)
|
||||
token = request.headers.get('token', None)
|
||||
application_uuid = request.headers.get('application_uuid', None)
|
||||
application_uuid = request.headers.get('application-uuid', None)
|
||||
|
||||
if remove_session(session_id, token, application_uuid):
|
||||
return Response(json.dumps({'result': 'succeed'}), status=200)
|
||||
@ -74,9 +77,9 @@ class KeepSessionAlive(Resource):
|
||||
|
||||
@staticmethod
|
||||
def put():
|
||||
session_id = request.headers.get('session_id', None)
|
||||
session_id = request.headers.get('session-id', None)
|
||||
token = request.headers.get('token', None)
|
||||
application_uuid = request.headers.get('application_uuid', None)
|
||||
application_uuid = request.headers.get('application-uuid', None)
|
||||
_session = refresh_session(session_id, token, application_uuid)
|
||||
|
||||
if _session is None:
|
||||
|
@ -43,7 +43,7 @@ paths:
|
||||
required: true
|
||||
description: the password for the user accessing this API
|
||||
- in: header
|
||||
name: application_uuid
|
||||
name: application-uuid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
@ -61,7 +61,7 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/login-succeed'
|
||||
headers:
|
||||
session_id:
|
||||
session-id:
|
||||
type: string
|
||||
format: uuid
|
||||
description: Session id
|
||||
@ -81,9 +81,9 @@ paths:
|
||||
/v1.4/session/keep-alive:
|
||||
put:
|
||||
security:
|
||||
- session_id: []
|
||||
- session-id: []
|
||||
- token: []
|
||||
- application_uuid: []
|
||||
- application-uuid: []
|
||||
parameters:
|
||||
[]
|
||||
tags:
|
||||
@ -114,9 +114,9 @@ paths:
|
||||
/v1.4/session/end:
|
||||
put:
|
||||
security:
|
||||
- session_id: []
|
||||
- session-id: []
|
||||
- token: []
|
||||
- application_uuid: []
|
||||
- application-uuid: []
|
||||
parameters:
|
||||
[]
|
||||
tags:
|
||||
@ -147,9 +147,9 @@ paths:
|
||||
/v1.4/persistence/retrofit-results:
|
||||
post:
|
||||
security:
|
||||
- session_id: [ ]
|
||||
- session-id: [ ]
|
||||
- token: [ ]
|
||||
- application_uuid: [ ]
|
||||
- application-uuid: [ ]
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
@ -162,7 +162,7 @@ paths:
|
||||
description: Cities list
|
||||
example: { "cities": [{ "Montreal current status": ["149_part_0_zone_0", "1_part_0_zone_0"]}]}
|
||||
tags:
|
||||
- Buildings monthly energy balance persistence
|
||||
- Persistence retrofit results
|
||||
summary: Retrieve the monthly energy balance results for the given persistence in the given cities
|
||||
operationId: retrofit_results
|
||||
description: Retrieve the monthly energy balance results for the given persistence in the given cities
|
||||
@ -189,9 +189,9 @@ paths:
|
||||
/v1.4/workflow/costs:
|
||||
post:
|
||||
security:
|
||||
- session_id: [ ]
|
||||
- session-id: [ ]
|
||||
- token: [ ]
|
||||
- application_uuid: [ ]
|
||||
- application-uuid: [ ]
|
||||
parameters:
|
||||
[ ]
|
||||
tags:
|
||||
@ -210,9 +210,9 @@ paths:
|
||||
/v1.4/workflow/energy-plus:
|
||||
post:
|
||||
security:
|
||||
- session_id: [ ]
|
||||
- session-id: [ ]
|
||||
- token: [ ]
|
||||
- application_uuid: [ ]
|
||||
- application-uuid: [ ]
|
||||
parameters:
|
||||
[ ]
|
||||
tags:
|
||||
@ -231,9 +231,9 @@ paths:
|
||||
/v1.4/workflow/insel-monthly-energy-balance:
|
||||
post:
|
||||
security:
|
||||
- session_id: [ ]
|
||||
- session-id: [ ]
|
||||
- token: [ ]
|
||||
- application_uuid: [ ]
|
||||
- application-uuid: [ ]
|
||||
parameters:
|
||||
[ ]
|
||||
tags:
|
||||
@ -250,14 +250,14 @@ paths:
|
||||
$ref: '#/components/schemas/not-implemented-error'
|
||||
components:
|
||||
securitySchemes:
|
||||
session_id:
|
||||
session-id:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: session_id
|
||||
application_uuid:
|
||||
name: session-id
|
||||
application-uuid:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: application_uuid
|
||||
name: application-uuid
|
||||
token:
|
||||
type: apiKey
|
||||
in: header
|
||||
|
@ -39,7 +39,7 @@ def _validate_session(session_id, token, application_uuid):
|
||||
_session = session(session_id)
|
||||
if debug_mode:
|
||||
token = _session['token']
|
||||
return bool(_session) and (_session['token'] == token) and _session['application_uuid'] == application_uuid
|
||||
return bool(_session) and (_session['token'] == token) and str(_session['application_uuid']) == application_uuid
|
||||
except KeyError:
|
||||
return False
|
||||
|
||||
|
@ -15,9 +15,9 @@ class RetrofitResults(Resource, Config):
|
||||
"""
|
||||
API call for requesting a specified list of enriched persistence
|
||||
"""
|
||||
session_id = request.headers.get('session_id', None)
|
||||
session_id = request.headers.get('session-id', None)
|
||||
token = request.headers.get('token', None)
|
||||
application_uuid = request.headers.get('application_uuid', None)
|
||||
application_uuid = request.headers.get('application-uuid', None)
|
||||
_session = refresh_session(session_id, token, application_uuid)
|
||||
if _session is None:
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
@ -26,7 +26,7 @@ class RetrofitResults(Resource, Config):
|
||||
user_id = session(session_id)['user_id']
|
||||
|
||||
payload = request.get_json()
|
||||
results = self.database.results.results(user_id, application_id, payload)
|
||||
results = self.database.results(user_id, application_id, payload)
|
||||
if results == {}:
|
||||
# no data found for the given parameters
|
||||
return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)
|
||||
@ -34,8 +34,9 @@ class RetrofitResults(Resource, Config):
|
||||
city_name = next(iter(results))
|
||||
for building_results in results[city_name]:
|
||||
values = []
|
||||
for value in building_results['insel persistence']:
|
||||
print(building_results)
|
||||
for value in building_results['insel meb']:
|
||||
key = next(iter(value))
|
||||
values.append({key: json.loads(value[key])})
|
||||
building_results['insel persistence'] = values
|
||||
values.append({key: json.loads(str(value[key]))})
|
||||
building_results['insel meb'] = values
|
||||
return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)
|
||||
|
Loading…
Reference in New Issue
Block a user