-
Notifications
You must be signed in to change notification settings - Fork 0
Feat(time-entries): include project name in time-entries response #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| def add_project_name_to_time_entries(time_entries, projects): | ||
| for time_entry in time_entries: | ||
| for project in projects: | ||
| if time_entry.project_id == project.id: | ||
| setattr(time_entry, 'project_name', project.name) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import abc | ||
| from dataclasses import dataclass, field | ||
| from typing import List, Callable | ||
| from flask import jsonify | ||
|
|
||
| from azure.cosmos import PartitionKey | ||
| from flask_restplus._http import HTTPStatus | ||
|
|
@@ -18,6 +19,10 @@ | |
| from commons.data_access_layer.database import EventContext | ||
|
|
||
| from time_tracker_api.time_entries.custom_modules import worked_time | ||
| from time_tracker_api.time_entries.custom_modules.utils import ( | ||
| add_project_name_to_time_entries, | ||
| ) | ||
| from time_tracker_api.projects import projects_model | ||
| from time_tracker_api.database import CRUDDao, APICosmosDBDao | ||
| from time_tracker_api.security import current_user_id | ||
|
|
||
|
|
@@ -106,6 +111,24 @@ def create_sql_date_range_filter(date_range: dict) -> str: | |
| else: | ||
| return '' | ||
|
|
||
| def find( | ||
| self, | ||
| id: str, | ||
| event_context: EventContext, | ||
| peeker: 'function' = None, | ||
| visible_only=True, | ||
| mapper: Callable = None, | ||
| ): | ||
| time_entry = CosmosDBRepository.find( | ||
| self, id, event_context, peeker, visible_only, mapper, | ||
| ) | ||
|
|
||
| project_dao = projects_model.create_dao() | ||
| project = project_dao.get(time_entry.project_id) | ||
| setattr(time_entry, 'project_name', project.name) | ||
|
|
||
| return time_entry | ||
|
|
||
| def find_all( | ||
| self, | ||
| event_context: EventContext, | ||
|
|
@@ -119,14 +142,18 @@ def find_all( | |
|
|
||
| custom_params = self.generate_params(date_range) | ||
|
|
||
| return CosmosDBRepository.find_all( | ||
| time_entries = CosmosDBRepository.find_all( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this returning the time-entries belonging to the JWT user or all of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. That is how it works. Check out the user_id/owner_id value is passed in the dictionary conditions, in the dao: |
||
| self, | ||
| event_context=event_context, | ||
| conditions=conditions, | ||
| custom_sql_conditions=custom_sql_conditions, | ||
| custom_params=custom_params, | ||
| ) | ||
|
|
||
| projects = project_dao.get_all() | ||
| add_project_name_to_time_entries(time_entries, projects) | ||
| return time_entries | ||
|
|
||
| def on_create(self, new_item_data: dict, event_context: EventContext): | ||
| CosmosDBRepository.on_create(self, new_item_data, event_context) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.