Skip to content

Commit ad11d88

Browse files
authored
Merge pull request #158 from ioet/156-include-activity-name
fix: #156 including activity name as part of the entries model
2 parents f7a612a + 4dc956e commit ad11d88

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
get_current_day,
2121
)
2222
from commons.data_access_layer.database import EventContext
23+
from time_tracker_api.activities import activities_model
2324

24-
from utils.extend_model import add_project_name_to_time_entries
25+
from utils.extend_model import add_project_name_to_time_entries, add_activity_name_to_time_entries
2526
from utils import worked_time
2627
from utils.worked_time import str_to_datetime
2728

@@ -174,6 +175,10 @@ def find_all(
174175
custom_sql_conditions=[custom_conditions]
175176
)
176177
add_project_name_to_time_entries(time_entries, projects)
178+
179+
activity_dao = activities_model.create_dao()
180+
activities = activity_dao.get_all()
181+
add_activity_name_to_time_entries(time_entries, activities)
177182
return time_entries
178183

179184
def on_create(self, new_item_data: dict, event_context: EventContext):

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@
122122
description='Name of the project where time-entry was registered',
123123
example=faker.word(['mobile app', 'web app']),
124124
),
125+
'activity_name': fields.String(
126+
required=False,
127+
title='Activity Name',
128+
max_length=50,
129+
description='Name of the activity associated with the time-entry',
130+
example=faker.word(['development', 'QA']),
131+
),
125132
}
126133
time_entry_response_fields.update(common_fields)
127134

utils/extend_model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ def add_project_name_to_time_entries(time_entries, projects):
2626
for project in projects:
2727
if time_entry.project_id == project.id:
2828
setattr(time_entry, 'project_name', project.name)
29+
30+
31+
def add_activity_name_to_time_entries(time_entries, activities):
32+
for time_entry in time_entries:
33+
for activity in activities:
34+
if time_entry.activity_id == activity.id:
35+
setattr(time_entry, 'activity_name', activity.name)

0 commit comments

Comments
 (0)