mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-07-16 18:13:16 +02:00
style: Refactoring imports, adapting MongoConnector to different connection_strings
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from News.utils.mongodb.mongo import MongoConnector
|
||||
from Unternehmensregister.models.Company import Company
|
||||
from Unternehmensregister.utils.CompanyServiceInterface import CompanyServiceInterface
|
||||
|
||||
|
||||
class CompanyMongoService(CompanyServiceInterface):
|
||||
def __init__(self, connector: MongoConnector):
|
||||
self.collection = connector.database["companies"]
|
||||
|
||||
def get_all(self) -> list[Company]:
|
||||
result = self.collection.find()
|
||||
return list(result)
|
||||
|
||||
def get_by_id(self, id: str) -> Company | None:
|
||||
result = list(self.collection.find({"id": id}))
|
||||
if len(result) == 1:
|
||||
return result[0]
|
||||
return None
|
||||
|
||||
def insert(self, company: Company):
|
||||
return self.collection.insert_one(company.dict())
|
@@ -0,0 +1,14 @@
|
||||
from abc import ABC
|
||||
|
||||
from models import Company
|
||||
|
||||
|
||||
class CompanyServiceInterface(ABC):
|
||||
def get_all(self) -> list[Company.Company]:
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_by_id(self, id: Company.CompayID) -> Company.Company | None:
|
||||
raise NotImplementedError()
|
||||
|
||||
def insert(self, company: Company.Company):
|
||||
raise NotImplementedError()
|
Reference in New Issue
Block a user