From a9e740d034bd73ea8642b51e298f39c934ea6bf7 Mon Sep 17 00:00:00 2001 From: Koa Date: Tue, 17 Jan 2023 19:15:18 -0500 Subject: [PATCH 1/2] Add skeleton for city commands and add API routes --- bootstrap.py | 7 +++++ hub_api/city_commands.py | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 hub_api/city_commands.py diff --git a/bootstrap.py b/bootstrap.py index 79f2d92..1f72e34 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -29,6 +29,7 @@ from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive from hub_api.uptime import Uptime from hub_api.greenery import Greenery from hub_api.user import User, UserLogin +from hub_api.city_commands import SaveCity, UpdateCity, DeleteCity, ListCities, SearchCity from flasgger import LazyJSONEncoder, LazyString, Swagger app = flask.Flask('gamification') @@ -81,4 +82,10 @@ api.add_resource(SessionEnd, '/v1.4/session/end') api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive') api.add_resource(CityInfo, '/v1.4/city_info') api.add_resource(City, '/v1.4/city') +api.add_resource(SaveCity, '/v1.4/city/save_city') +api.add_resource(UpdateCity, '/v1.4/city/update_city') +api.add_resource(DeleteCity, '/v1.4/city/delete_city') +api.add_resource(ListCities, '/v1.4/city/list_cities') +api.add_resource(SearchCity, '/v1.4/city/search_city') api.add_resource(Greenery, '/v1.4/greenery') + diff --git a/hub_api/city_commands.py b/hub_api/city_commands.py new file mode 100644 index 0000000..dbf3522 --- /dev/null +++ b/hub_api/city_commands.py @@ -0,0 +1,62 @@ +""" +HeatPump Service +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2023 Project Author Koa Wells kekoa.wells@concordia.ca +""" + +import json +from flask import Response, request +from flask_restful import Resource +from imports.user_factory import UserFactory +from exports.user_factory import UserFactory as ExUserFactory +import os +from hub_logger import logger +from hub_api.helpers.auth import generate_auth_token, role_required +from persistence.models import UserRoles + +#Admin commands + +class SaveCity(Resource): + def __init__(self): + print() + + @role_required([UserRoles.Admin.value]) + def put(self): + + +class UpdateCity(Resource): + def __init__(self): + print() + + @role_required([UserRoles.Admin.value]) + def put(self): + + class UpdateCity(Resource): + +class DeleteCity(Resource): + def __init__(self): + print() + + @role_required([UserRoles.Admin.value]) + def delete(self): + +#Standard user commands + +class ListCities(Resource): + def __init__(self): + print() + + @role_required([UserRoles.Admin.value]) + def put(self): + +class SearchCity(Resource): + def __init__(self): + print() + + def get(self): + + class UpdateCity(Resource): + def __init__(self): + print() + + def get(self): \ No newline at end of file From 4628686d400497c560e457eee96e43da10065237 Mon Sep 17 00:00:00 2001 From: Koa Date: Tue, 17 Jan 2023 19:17:18 -0500 Subject: [PATCH 2/2] Update skeleton --- hub_api/city_commands.py | 60 ++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/hub_api/city_commands.py b/hub_api/city_commands.py index dbf3522..e190ec3 100644 --- a/hub_api/city_commands.py +++ b/hub_api/city_commands.py @@ -11,52 +11,88 @@ from imports.user_factory import UserFactory from exports.user_factory import UserFactory as ExUserFactory import os from hub_logger import logger +from hub_api.helpers.session_helper import refresh_session from hub_api.helpers.auth import generate_auth_token, role_required from persistence.models import UserRoles -#Admin commands - +#Admin user commands +""" +SaveCity class +""" class SaveCity(Resource): def __init__(self): print() @role_required([UserRoles.Admin.value]) def put(self): + session = refresh_session(request) + if session is None: + return Response(json.dumps({'error': 'invalid session'}), status=401) + headers = session.headers +""" +UpdateCity class +""" class UpdateCity(Resource): def __init__(self): print() @role_required([UserRoles.Admin.value]) def put(self): - - class UpdateCity(Resource): - + session = refresh_session(request) + if session is None: + return Response(json.dumps({'error': 'invalid session'}), status=401) + headers = session.headers +""" +DeleteCity class +""" class DeleteCity(Resource): def __init__(self): print() @role_required([UserRoles.Admin.value]) def delete(self): + session = refresh_session(request) + if session is None: + return Response(json.dumps({'error': 'invalid session'}), status=401) + headers = session.headers #Standard user commands - +""" +ListCities class +""" class ListCities(Resource): def __init__(self): print() @role_required([UserRoles.Admin.value]) def put(self): - + session = refresh_session(request) + if session is None: + return Response(json.dumps({'error': 'invalid session'}), status=401) + headers = session.headers +""" +SearchCity class +""" class SearchCity(Resource): def __init__(self): print() def get(self): + session = refresh_session(request) + if session is None: + return Response(json.dumps({'error': 'invalid session'}), status=401) + headers = session.headers +""" +UpdateCity class +""" +class UpdateCity(Resource): + def __init__(self): + print() - class UpdateCity(Resource): - def __init__(self): - print() - - def get(self): \ No newline at end of file + def get(self): + session = refresh_session(request) + if session is None: + return Response(json.dumps({'error': 'invalid session'}), status=401) + headers = session.headers \ No newline at end of file