Merge remote-tracking branch 'origin/city_commands' into api_guille
# Conflicts: # bootstrap.py
This commit is contained in:
commit
72c265cd88
34
bootstrap.py
34
bootstrap.py
|
@ -45,30 +45,12 @@ api.add_resource(UserLogin, '/v1.4/user/login')
|
|||
api.add_resource(SessionStart, '/v1.4/session/start')
|
||||
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')
|
||||
|
||||
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
|
||||
swagger_config = {
|
||||
"headers": [],
|
||||
"specs": [
|
||||
{
|
||||
"endpoint": 'apispec',
|
||||
"route": '/apispec.json',
|
||||
"rule_filter": lambda rule: True, # all in
|
||||
"model_filter": lambda tag: True, # all in
|
||||
}
|
||||
],
|
||||
"static_url_path": "/flasgger_static",
|
||||
"specs_route": "/v1.4/api-docs/",
|
||||
"openapi": "3.0.0"
|
||||
}
|
||||
try:
|
||||
Swagger(app, template=yaml.safe_load(stream), config=swagger_config)
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return Response(headers={'Access-Control-Allow-Origin': '*'})
|
||||
|
||||
app.run(port=15789, host="0.0.0.0", debug=True)
|
||||
|
|
98
hub_api/city_commands.py
Normal file
98
hub_api/city_commands.py
Normal file
|
@ -0,0 +1,98 @@
|
|||
"""
|
||||
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.session_helper import refresh_session
|
||||
from hub_api.helpers.auth import generate_auth_token, role_required
|
||||
from persistence.models import UserRoles
|
||||
|
||||
#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):
|
||||
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()
|
||||
|
||||
def get(self):
|
||||
session = refresh_session(request)
|
||||
if session is None:
|
||||
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
||||
headers = session.headers
|
Loading…
Reference in New Issue
Block a user