Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(projects): ✨ add customer name to projects
  • Loading branch information
Angeluz-07 committed May 19, 2020
commit 5e9c3234c1913bcd1b7117d16783c8ff9baa9e56
9 changes: 9 additions & 0 deletions time_tracker_api/projects/custom_modules/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TODO this must be refactored to be used from the utils module ↓
# Also check if we can change this using the overwritten __add__ method


def add_customer_name_to_projects(projects, customers):
for project in projects:
for customer in customers:
if project.customer_id == customer.id:
setattr(project, 'customer_name', customer.name)
11 changes: 9 additions & 2 deletions time_tracker_api/projects/projects_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from time_tracker_api.customers.customers_model import create_dao as customers_create_dao
from time_tracker_api.customers.customers_model import CustomerCosmosDBModel

from time_tracker_api.projects.custom_modules.utils import (
add_customer_name_to_projects
)

class ProjectDao(CRUDDao):
pass
Expand Down Expand Up @@ -73,11 +76,15 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
customers_id = [customer.id for customer in customers]
conditions = conditions if conditions else {}
custom_condition = "c.customer_id IN {}".format(str(tuple(customers_id)))
# TODO this must be refactored to be used from the utils module ↑
if "custom_sql_conditions" in kwargs:
kwargs["custom_sql_conditions"].append(custom_condition)
else:
kwargs["custom_sql_conditions"] = [custom_condition]
return self.repository.find_all(event_ctx, conditions, **kwargs)
kwargs["custom_sql_conditions"] = [custom_condition]
projects = self.repository.find_all(event_ctx, conditions, **kwargs)

add_customer_name_to_projects(projects, customers)
return projects


def create_dao() -> ProjectDao:
Expand Down
10 changes: 9 additions & 1 deletion time_tracker_api/projects/projects_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@
)
})

project_response_fields = {}
project_response_fields = {
'customer_name': fields.String(
required=True,
title='Customer Name',
max_length=50,
description='Name of the customer of the project',
example=faker.company(),
),
}
project_response_fields.update(common_fields)

project = ns.inherit(
Expand Down
4 changes: 4 additions & 0 deletions time_tracker_api/time_entries/custom_modules/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TODO this must be refactored to be used from the utils module ↓
# Also check if we can improve this by using the overwritten __add__ method


def add_project_name_to_time_entries(time_entries, projects):
for time_entry in time_entries:
for project in projects:
Expand Down