39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""
|
|
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
|
|
"""
|
|
from hub.city_model_structure.city import City
|
|
from hub.persistence import City as CityRepository
|
|
|
|
|
|
class DBFactory:
|
|
"""
|
|
DBFactory class
|
|
"""
|
|
|
|
def __init__(self, db_name, dotenv_path, app_env):
|
|
self._city_repository = CityRepository(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
|
|
|
|
def persist_city(self, application_id: int, user_id: int, city: City):
|
|
"""
|
|
Persist city into postgres database
|
|
"""
|
|
return self._city_repository.insert(city, application_id, user_id)
|
|
|
|
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
|
|
"""
|
|
return self._city_repository.update(city_id, city)
|
|
|
|
def delete_city(self, city_id):
|
|
"""
|
|
Deletes a single city from postgres
|
|
:param city_id: the id of the city to get
|
|
"""
|
|
self._city_repository.delete(city_id)
|