From 582c18ef0c49e61b55d133be1ee16baf68b74f25 Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Tue, 17 Jan 2023 20:10:20 -0500 Subject: [PATCH 1/2] included db import reference to config --- hub_api/city_info.py | 12 +++++------- hub_api/config.py | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hub_api/city_info.py b/hub_api/city_info.py index 080dece..4a356aa 100644 --- a/hub_api/city_info.py +++ b/hub_api/city_info.py @@ -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: diff --git a/hub_api/config.py b/hub_api/config.py index 1ca930e..6e970a2 100644 --- a/hub_api/config.py +++ b/hub_api/config.py @@ -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 @@ -13,6 +14,8 @@ class Config: def __init__(self): self.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) From c462d75e084b1b711bde4e4034810035853ba580 Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Tue, 17 Jan 2023 20:13:54 -0500 Subject: [PATCH 2/2] Renamed export factory --- hub_api/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hub_api/config.py b/hub_api/config.py index 6e970a2..aa68fd3 100644 --- a/hub_api/config.py +++ b/hub_api/config.py @@ -12,13 +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