Skip to content

Commit b6ee255

Browse files
authored
Merge pull request #134 from ioet/feature/include-project-name-in-time-entry-response#129
Feat(time-entries): include project name in time-entries response
2 parents 4ed6289 + c26459b commit b6ee255

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def add_project_name_to_time_entries(time_entries, projects):
2+
for time_entry in time_entries:
3+
for project in projects:
4+
if time_entry.project_id == project.id:
5+
setattr(time_entry, 'project_name', project.name)

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22
from dataclasses import dataclass, field
33
from typing import List, Callable
4+
from flask import jsonify
45

56
from azure.cosmos import PartitionKey
67
from flask_restplus._http import HTTPStatus
@@ -18,6 +19,10 @@
1819
from commons.data_access_layer.database import EventContext
1920

2021
from time_tracker_api.time_entries.custom_modules import worked_time
22+
from time_tracker_api.time_entries.custom_modules.utils import (
23+
add_project_name_to_time_entries,
24+
)
25+
from time_tracker_api.projects import projects_model
2126
from time_tracker_api.database import CRUDDao, APICosmosDBDao
2227
from time_tracker_api.security import current_user_id
2328

@@ -106,6 +111,24 @@ def create_sql_date_range_filter(date_range: dict) -> str:
106111
else:
107112
return ''
108113

114+
def find(
115+
self,
116+
id: str,
117+
event_context: EventContext,
118+
peeker: 'function' = None,
119+
visible_only=True,
120+
mapper: Callable = None,
121+
):
122+
time_entry = CosmosDBRepository.find(
123+
self, id, event_context, peeker, visible_only, mapper,
124+
)
125+
126+
project_dao = projects_model.create_dao()
127+
project = project_dao.get(time_entry.project_id)
128+
setattr(time_entry, 'project_name', project.name)
129+
130+
return time_entry
131+
109132
def find_all(
110133
self,
111134
event_context: EventContext,
@@ -119,14 +142,18 @@ def find_all(
119142

120143
custom_params = self.generate_params(date_range)
121144

122-
return CosmosDBRepository.find_all(
145+
time_entries = CosmosDBRepository.find_all(
123146
self,
124147
event_context=event_context,
125148
conditions=conditions,
126149
custom_sql_conditions=custom_sql_conditions,
127150
custom_params=custom_params,
128151
)
129152

153+
projects = project_dao.get_all()
154+
add_project_name_to_time_entries(time_entries, projects)
155+
return time_entries
156+
130157
def on_create(self, new_item_data: dict, event_context: EventContext):
131158
CosmosDBRepository.on_create(self, new_item_data, event_context)
132159

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
description='User who owns the time entry',
116116
example=faker.uuid4(),
117117
),
118+
'project_name': fields.String(
119+
required=True,
120+
title='Project Name',
121+
max_length=50,
122+
description='Name of the project where time-entry was registered',
123+
example=faker.word(['mobile app', 'web app']),
124+
),
118125
}
119126
time_entry_response_fields.update(common_fields)
120127

0 commit comments

Comments
 (0)