Skip to content

Commit 5e9c323

Browse files
committed
feat(projects): ✨ add customer name to projects
1 parent 5d07002 commit 5e9c323

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# TODO this must be refactored to be used from the utils module ↓
2+
# Also check if we can change this using the overwritten __add__ method
3+
4+
5+
def add_customer_name_to_projects(projects, customers):
6+
for project in projects:
7+
for customer in customers:
8+
if project.customer_id == customer.id:
9+
setattr(project, 'customer_name', customer.name)

time_tracker_api/projects/projects_model.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from time_tracker_api.customers.customers_model import create_dao as customers_create_dao
66
from time_tracker_api.customers.customers_model import CustomerCosmosDBModel
77

8+
from time_tracker_api.projects.custom_modules.utils import (
9+
add_customer_name_to_projects
10+
)
811

912
class ProjectDao(CRUDDao):
1013
pass
@@ -73,11 +76,15 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
7376
customers_id = [customer.id for customer in customers]
7477
conditions = conditions if conditions else {}
7578
custom_condition = "c.customer_id IN {}".format(str(tuple(customers_id)))
79+
# TODO this must be refactored to be used from the utils module ↑
7680
if "custom_sql_conditions" in kwargs:
7781
kwargs["custom_sql_conditions"].append(custom_condition)
7882
else:
79-
kwargs["custom_sql_conditions"] = [custom_condition]
80-
return self.repository.find_all(event_ctx, conditions, **kwargs)
83+
kwargs["custom_sql_conditions"] = [custom_condition]
84+
projects = self.repository.find_all(event_ctx, conditions, **kwargs)
85+
86+
add_customer_name_to_projects(projects, customers)
87+
return projects
8188

8289

8390
def create_dao() -> ProjectDao:

time_tracker_api/projects/projects_namespace.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@
4848
)
4949
})
5050

51-
project_response_fields = {}
51+
project_response_fields = {
52+
'customer_name': fields.String(
53+
required=True,
54+
title='Customer Name',
55+
max_length=50,
56+
description='Name of the customer of the project',
57+
example=faker.company(),
58+
),
59+
}
5260
project_response_fields.update(common_fields)
5361

5462
project = ns.inherit(

time_tracker_api/time_entries/custom_modules/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# TODO this must be refactored to be used from the utils module ↓
2+
# Also check if we can improve this by using the overwritten __add__ method
3+
4+
15
def add_project_name_to_time_entries(time_entries, projects):
26
for time_entry in time_entries:
37
for project in projects:

0 commit comments

Comments
 (0)