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