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
fix: #156 including activity name as part of the entries model
  • Loading branch information
enriquezrene committed Jun 1, 2020
commit 4dc956eeeed46d44321f68e002d6ed51eb689577
7 changes: 6 additions & 1 deletion time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
get_current_day,
)
from commons.data_access_layer.database import EventContext
from time_tracker_api.activities import activities_model

from utils.extend_model import add_project_name_to_time_entries
from utils.extend_model import add_project_name_to_time_entries, add_activity_name_to_time_entries
from utils import worked_time
from utils.worked_time import str_to_datetime

Expand Down Expand Up @@ -174,6 +175,10 @@ def find_all(
custom_sql_conditions=[custom_conditions]
)
add_project_name_to_time_entries(time_entries, projects)

activity_dao = activities_model.create_dao()
activities = activity_dao.get_all()
add_activity_name_to_time_entries(time_entries, activities)
return time_entries

def on_create(self, new_item_data: dict, event_context: EventContext):
Expand Down
7 changes: 7 additions & 0 deletions time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@
description='Name of the project where time-entry was registered',
example=faker.word(['mobile app', 'web app']),
),
'activity_name': fields.String(
required=False,
title='Activity Name',
max_length=50,
description='Name of the activity associated with the time-entry',
example=faker.word(['development', 'QA']),
),
}
time_entry_response_fields.update(common_fields)

Expand Down
7 changes: 7 additions & 0 deletions utils/extend_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ def add_project_name_to_time_entries(time_entries, projects):
for project in projects:
if time_entry.project_id == project.id:
setattr(time_entry, 'project_name', project.name)


def add_activity_name_to_time_entries(time_entries, activities):
for time_entry in time_entries:
for activity in activities:
if time_entry.activity_id == activity.id:
setattr(time_entry, 'activity_name', activity.name)