Update bootstrap.py
This commit is contained in:
parent
783731a9ba
commit
7b6620eca0
@ -12,9 +12,9 @@ from hub_api.city_info import CityInfo, City
|
||||
from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
|
||||
from hub_api.uptime import Uptime
|
||||
from hub_api.user import User, UserLogin
|
||||
from hub_api.city_commands import SaveCity, UpdateCity, DeleteCity, ListCities, SearchCity
|
||||
from flasgger import LazyJSONEncoder, Swagger
|
||||
from flask import Response
|
||||
from hub_api.city_commands import UpdateCity, DeleteCity, ListCities, SearchCity
|
||||
from flasgger import LazyJSONEncoder, LazyString, Swagger
|
||||
|
||||
app = flask.Flask('gamification')
|
||||
app.json_encoder = LazyJSONEncoder
|
||||
@ -48,7 +48,6 @@ api.add_resource(SessionEnd, '/v1.4/session/end')
|
||||
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
|
||||
api.add_resource(CityInfo, '/v1.4/city/<int:city_id>')
|
||||
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')
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""
|
||||
HeatPump Service
|
||||
City Commands
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2023 Project Author Koa Wells kekoa.wells@concordia.ca
|
||||
"""
|
||||
@ -7,11 +7,10 @@ Copyright © 2023 Project Author Koa Wells kekoa.wells@concordia.ca
|
||||
import json
|
||||
from flask import Response, request
|
||||
from flask_restful import Resource
|
||||
from hub_api import session
|
||||
from hub_api.helpers.session_helper import refresh_session
|
||||
from hub_api.helpers.auth import role_required
|
||||
import os
|
||||
from imports.db_factory import DBFactory
|
||||
from imports.user_factory import UserFactory
|
||||
from imports.geometry_factory import GeometryFactory
|
||||
from hub_logger import logger
|
||||
from persistence.models import UserRoles
|
||||
@ -20,26 +19,9 @@ import os
|
||||
|
||||
# Admin user commands
|
||||
|
||||
# class SaveCity(Resource):
|
||||
# """
|
||||
# SaveCity class performs an admin API call to save an instantiated city into the database
|
||||
# """
|
||||
#
|
||||
# def __init__(self):
|
||||
# self.db_factory = DBFactory(db_name='hub_prod', app_env='PROD',
|
||||
# dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
#
|
||||
# # todo: implement feature to persist instantiated city into database
|
||||
# @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
|
||||
|
||||
class UpdateCity(Resource):
|
||||
"""
|
||||
UpdateCity class performs an admin API call to update a city that already exists inside the database
|
||||
UpdateCity class performs an API call to update a city that already exists inside the database
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
@ -48,9 +30,6 @@ class UpdateCity(Resource):
|
||||
|
||||
@role_required([UserRoles.Admin.value])
|
||||
def put(self, city_id):
|
||||
session = refresh_session(request)
|
||||
if session is None:
|
||||
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
||||
headers = session.headers
|
||||
|
||||
allowed_ext = {'gml', '3dm', 'xml', 'obj', 'rhino'}
|
||||
@ -70,7 +49,7 @@ class UpdateCity(Resource):
|
||||
city_file.save(file_path)
|
||||
city = GeometryFactory(city_file_type, file_path).city
|
||||
|
||||
saved_city = self.db_factory.update_city(city.city_id, city)
|
||||
saved_city = self.db_factory.update_city(city_id, city)
|
||||
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
@ -105,10 +84,6 @@ class DeleteCity(Resource):
|
||||
|
||||
@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)
|
||||
|
||||
try:
|
||||
payload = request.get_json()
|
||||
return Response(json.dumps(response=DBFactory.delete_city(city_id=payload["city_id"]), status=201))
|
||||
@ -129,10 +104,7 @@ class ListCities(Resource):
|
||||
dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
|
||||
def get(self):
|
||||
session = refresh_session(request)
|
||||
if session is None:
|
||||
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
||||
headers = session.headers
|
||||
pass
|
||||
|
||||
class SearchCity(Resource):
|
||||
"""
|
||||
@ -144,7 +116,4 @@ class SearchCity(Resource):
|
||||
dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
|
||||
def get(self, city_id):
|
||||
session = refresh_session(request)
|
||||
if session is None:
|
||||
return Response(json.dumps({'error': 'invalid session'}), status=401)
|
||||
headers = session.headers
|
||||
pass
|
||||
|
@ -15,7 +15,7 @@ paths:
|
||||
- city
|
||||
summary: Create a city
|
||||
operationId: createCity
|
||||
description: Create a new city with a file upoload
|
||||
description: Create a new city with a file upload
|
||||
parameters:
|
||||
- in: header
|
||||
name: appId
|
||||
|
Loading…
Reference in New Issue
Block a user