2023-01-17 19:15:18 -05:00
|
|
|
"""
|
|
|
|
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
|
2023-01-17 19:17:18 -05:00
|
|
|
from hub_api.helpers.session_helper import refresh_session
|
2023-01-17 19:15:18 -05:00
|
|
|
from hub_api.helpers.auth import generate_auth_token, role_required
|
|
|
|
from persistence.models import UserRoles
|
|
|
|
|
2023-01-17 19:17:18 -05:00
|
|
|
#Admin user commands
|
|
|
|
"""
|
|
|
|
SaveCity class
|
|
|
|
"""
|
2023-01-17 19:15:18 -05:00
|
|
|
class SaveCity(Resource):
|
|
|
|
def __init__(self):
|
|
|
|
print()
|
|
|
|
|
|
|
|
@role_required([UserRoles.Admin.value])
|
|
|
|
def put(self):
|
2023-01-17 19:17:18 -05:00
|
|
|
session = refresh_session(request)
|
|
|
|
if session is None:
|
|
|
|
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
|
|
|
headers = session.headers
|
2023-01-17 19:15:18 -05:00
|
|
|
|
|
|
|
|
2023-01-17 19:17:18 -05:00
|
|
|
"""
|
|
|
|
UpdateCity class
|
|
|
|
"""
|
2023-01-17 19:15:18 -05:00
|
|
|
class UpdateCity(Resource):
|
|
|
|
def __init__(self):
|
|
|
|
print()
|
|
|
|
|
|
|
|
@role_required([UserRoles.Admin.value])
|
|
|
|
def put(self):
|
2023-01-17 19:17:18 -05:00
|
|
|
session = refresh_session(request)
|
|
|
|
if session is None:
|
|
|
|
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
|
|
|
headers = session.headers
|
|
|
|
"""
|
|
|
|
DeleteCity class
|
|
|
|
"""
|
2023-01-17 19:15:18 -05:00
|
|
|
class DeleteCity(Resource):
|
|
|
|
def __init__(self):
|
|
|
|
print()
|
|
|
|
|
|
|
|
@role_required([UserRoles.Admin.value])
|
|
|
|
def delete(self):
|
2023-01-17 19:17:18 -05:00
|
|
|
session = refresh_session(request)
|
|
|
|
if session is None:
|
|
|
|
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
|
|
|
headers = session.headers
|
2023-01-17 19:15:18 -05:00
|
|
|
|
|
|
|
#Standard user commands
|
2023-01-17 19:17:18 -05:00
|
|
|
"""
|
|
|
|
ListCities class
|
|
|
|
"""
|
2023-01-17 19:15:18 -05:00
|
|
|
class ListCities(Resource):
|
|
|
|
def __init__(self):
|
|
|
|
print()
|
|
|
|
|
|
|
|
@role_required([UserRoles.Admin.value])
|
|
|
|
def put(self):
|
2023-01-17 19:17:18 -05:00
|
|
|
session = refresh_session(request)
|
|
|
|
if session is None:
|
|
|
|
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
|
|
|
headers = session.headers
|
|
|
|
"""
|
|
|
|
SearchCity class
|
|
|
|
"""
|
2023-01-17 19:15:18 -05:00
|
|
|
class SearchCity(Resource):
|
|
|
|
def __init__(self):
|
|
|
|
print()
|
|
|
|
|
|
|
|
def get(self):
|
2023-01-17 19:17:18 -05:00
|
|
|
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()
|
2023-01-17 19:15:18 -05:00
|
|
|
|
2023-01-17 19:17:18 -05:00
|
|
|
def get(self):
|
|
|
|
session = refresh_session(request)
|
|
|
|
if session is None:
|
|
|
|
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
|
|
|
headers = session.headers
|