Basic integration of city persistence commands
This commit is contained in:
parent
72c265cd88
commit
86a720dfbe
40
bootstrap.py
40
bootstrap.py
|
@ -20,6 +20,8 @@ from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
|
|||
from hub_api.uptime import Uptime
|
||||
from hub_api.usage_catalog import UsageCatalogEntry, UsageCatalogEntries, UsageCatalogNames
|
||||
from hub_api.user import User, UserLogin
|
||||
from hub_api.city_info import CityInfo, City
|
||||
from hub_api.city_commands import Update, Delete, Search, List, Save
|
||||
|
||||
sh.begin_time = datetime.datetime.now()
|
||||
app = flask.Flask('cerc_api')
|
||||
|
@ -47,10 +49,36 @@ 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')
|
||||
api.add_resource(Save, '/v1.4/city/save_city')
|
||||
api.add_resource(Update, '/v1.4/city/update_city')
|
||||
api.add_resource(Delete, '/v1.4/city/delete_city')
|
||||
api.add_resource(List, '/v1.4/city/list_cities')
|
||||
api.add_resource(Search, '/v1.4/city/search_city')
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
@ -5,94 +5,82 @@ 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.persistence.models import UserRoles
|
||||
|
||||
from hub_api.helpers.auth import role_required
|
||||
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
|
||||
# Admin user commands
|
||||
"""
|
||||
SaveCity class
|
||||
Save class
|
||||
"""
|
||||
class SaveCity(Resource):
|
||||
def __init__(self):
|
||||
print()
|
||||
class Save(Resource):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@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
|
||||
@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
|
||||
Update class
|
||||
"""
|
||||
class UpdateCity(Resource):
|
||||
def __init__(self):
|
||||
print()
|
||||
class Update(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
|
||||
@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
|
||||
Delete class
|
||||
"""
|
||||
class DeleteCity(Resource):
|
||||
def __init__(self):
|
||||
print()
|
||||
class Delete(Resource):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@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
|
||||
@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
|
||||
# Standard user commands
|
||||
"""
|
||||
ListCities class
|
||||
"""
|
||||
class ListCities(Resource):
|
||||
def __init__(self):
|
||||
print()
|
||||
class List(Resource):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@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
|
||||
|
||||
@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()
|
||||
class Search(Resource):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
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
|
||||
|
||||
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