mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-14 02:58:45 +02:00
22 lines
753 B
Python
22 lines
753 B
Python
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())
|