2022-11-15 20:48:42 -05:00
|
|
|
"""
|
|
|
|
DBFactory performs database create, delete and update operations
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project CoderPeter Yefi peteryefi@gmail.com
|
|
|
|
"""
|
2023-01-24 10:51:50 -05:00
|
|
|
from hub.city_model_structure.city import City
|
2023-02-02 06:12:24 -05:00
|
|
|
from hub.persistence import City as CityRepository
|
2022-11-15 20:48:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
class DBFactory:
|
|
|
|
"""
|
|
|
|
DBFactory class
|
|
|
|
"""
|
|
|
|
|
2023-01-17 20:04:56 -05:00
|
|
|
def __init__(self, db_name, dotenv_path, app_env):
|
2023-02-02 06:12:24 -05:00
|
|
|
self._city_repository = CityRepository(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
|
2022-11-15 20:48:42 -05:00
|
|
|
|
2023-02-02 06:12:24 -05:00
|
|
|
def persist_city(self, application_id: int, user_id: int, city: City):
|
2022-11-15 20:48:42 -05:00
|
|
|
"""
|
|
|
|
Persist city into postgres database
|
|
|
|
"""
|
2023-02-02 06:12:24 -05:00
|
|
|
return self._city_repository.insert(city, application_id, user_id)
|
2022-11-15 20:48:42 -05:00
|
|
|
|
|
|
|
def update_city(self, city_id, city):
|
|
|
|
"""
|
|
|
|
Update an existing city in postgres database
|
|
|
|
:param city_id: the id of the city to update
|
|
|
|
:param city: the updated city object
|
|
|
|
"""
|
2023-02-02 06:12:24 -05:00
|
|
|
return self._city_repository.update(city_id, city)
|
2022-11-15 20:48:42 -05:00
|
|
|
|
|
|
|
def delete_city(self, city_id):
|
|
|
|
"""
|
|
|
|
Deletes a single city from postgres
|
|
|
|
:param city_id: the id of the city to get
|
|
|
|
"""
|
2023-02-02 06:12:24 -05:00
|
|
|
self._city_repository.delete(city_id)
|