Merge pull request 'api-v2' (#5) from api-v2 into main
Reviewed-on: https://nextgenerations-cities.encs.concordia.ca/gitea/p_yefi/gamification_service_v2/pulls/5
This commit is contained in:
commit
d73d77fbe4
|
@ -12,7 +12,6 @@ from persistence.models import UserRoles
|
|||
from hub_logger import logger
|
||||
from imports.geometry_factory import GeometryFactory
|
||||
from pathlib import Path
|
||||
from imports.db_factory import DBFactory
|
||||
import os
|
||||
from hub_api.config import Config
|
||||
|
||||
|
@ -74,12 +73,12 @@ class CityInfo(Resource, Config):
|
|||
return Response(json.dumps(response), status=200)
|
||||
|
||||
|
||||
class City(Resource):
|
||||
class City(Resource, Config):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
super().__init__()
|
||||
|
||||
@role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value])
|
||||
@role_required([UserRoles.Admin.value])
|
||||
def post(self):
|
||||
allowed_ext = {'gml', '3dm', 'xml', 'obj', 'rhino'}
|
||||
try:
|
||||
|
@ -96,9 +95,8 @@ class City(Resource):
|
|||
file_path = (Path(__file__).parent.parent / 'data/uploaded_city/{}'.format(city_file.filename)).resolve()
|
||||
city_file.save(file_path)
|
||||
city = GeometryFactory(city_file_type, file_path).city
|
||||
db_factory = DBFactory(city=city, db_name='hub_prod', app_env='PROD',
|
||||
dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
saved_city = db_factory.persist_city(1)
|
||||
|
||||
saved_city = self.import_db_factory.persist_city(g.user['id'], city)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
if type(saved_city) is not dict:
|
||||
|
|
|
@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2023 Project Peter Yefi peteryefi@gmail.com
|
||||
"""
|
||||
from exports.db_factory import DBFactory as CityExportFactory
|
||||
from imports.db_factory import DBFactory
|
||||
import os
|
||||
import pickle
|
||||
|
||||
|
@ -11,11 +12,13 @@ import pickle
|
|||
class Config:
|
||||
|
||||
def __init__(self):
|
||||
self.factory = CityExportFactory(db_name='hub_prod', app_env='PROD',
|
||||
dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
self.export_db_factory = CityExportFactory(db_name='hub_prod', app_env='PROD',
|
||||
dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
self.import_db_factory = DBFactory(db_name='hub_prod', app_env='PROD',
|
||||
dotenv_path="{}/.env".format(os.path.expanduser('~')))
|
||||
|
||||
def get_city(self, city_id):
|
||||
city_obj = self.factory.get_city(city_id)
|
||||
city_obj = self.export_db_factory.get_city(city_id)
|
||||
city = pickle.loads(city_obj.city)
|
||||
for building in city.buildings:
|
||||
building.heated = True
|
||||
|
|
Loading…
Reference in New Issue
Block a user