Skip to content

Commit 979e103

Browse files
committed
fix: Refactor the project module #121
1 parent abb02bd commit 979e103

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

time_tracker_api/projects/projects_model.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from dataclasses import dataclass
2-
32
from azure.cosmos import PartitionKey
4-
53
from commons.data_access_layer.cosmos_db import CosmosDBModel, CosmosDBDao, CosmosDBRepository
64
from time_tracker_api.database import CRUDDao, APICosmosDBDao
5+
from time_tracker_api.customers.customers_model import create_dao as customers_create_dao
76

87

98
class ProjectDao(CRUDDao):
@@ -41,12 +40,29 @@ def __str___(self):
4140
return "the project \"%s\"" % self.name # pragma: no cover
4241

4342

44-
def create_dao() -> ProjectDao:
45-
repository = CosmosDBRepository.from_definition(container_definition,
46-
mapper=ProjectCosmosDBModel)
43+
class ProjectCosmosDBRepository(CosmosDBRepository):
44+
def __init__(self):
45+
CosmosDBRepository.__init__(self, container_id=container_definition['id'],
46+
partition_key_attribute='tenant_id',
47+
mapper=ProjectCosmosDBModel)
48+
49+
50+
class ProjectCosmosDBDao(APICosmosDBDao, ProjectDao):
51+
def __init__(self, repository):
52+
CosmosDBDao.__init__(self, repository)
4753

48-
class ProjectCosmosDBDao(APICosmosDBDao, ProjectDao):
49-
def __init__(self):
50-
CosmosDBDao.__init__(self, repository)
54+
def get_all(self, conditions: dict = None, **kwargs) -> list:
55+
event_ctx = self.create_event_context("read-many")
56+
customer_dao = customers_create_dao()
57+
customers = customer_dao.get_all(visible_only=False)
58+
projects = self.repository.find_all(event_ctx, **kwargs)
59+
for project in projects:
60+
print(project.__dict__)
61+
62+
return projects
63+
64+
65+
def create_dao() -> ProjectDao:
66+
repository = ProjectCosmosDBRepository()
5167

52-
return ProjectCosmosDBDao()
68+
return ProjectCosmosDBDao(repository)

0 commit comments

Comments
 (0)