-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Create end point last entries #215 #221
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,8 @@ def find_all_entries( | |
| conditions=conditions, | ||
| custom_sql_conditions=custom_sql_conditions, | ||
| custom_params=custom_params, | ||
| max_count=kwargs.get("max_count", None), | ||
| offset=kwargs.get("offset", 0), | ||
| ) | ||
| return time_entries | ||
|
|
||
|
|
@@ -173,6 +175,7 @@ def count( | |
| conditions: dict = None, | ||
| custom_sql_conditions: List[str] = None, | ||
| date_range: dict = None, | ||
| **kwargs, | ||
| ): | ||
| conditions = conditions if conditions else {} | ||
| custom_sql_conditions = ( | ||
|
|
@@ -424,7 +427,8 @@ def get_all(self, conditions: dict = None, **kwargs) -> list: | |
| conditions.update({"owner_id": event_ctx.user_id}) | ||
|
|
||
| custom_query = self.build_custom_query( | ||
| is_admin=event_ctx.is_admin, conditions=conditions, | ||
| is_admin=event_ctx.is_admin, | ||
| conditions=conditions, | ||
| ) | ||
| date_range = self.handle_date_filter_args(args=conditions) | ||
| limit = conditions.get("limit", None) | ||
|
|
@@ -437,14 +441,56 @@ def get_all(self, conditions: dict = None, **kwargs) -> list: | |
| max_count=limit, | ||
| ) | ||
|
|
||
| def get_last_projects_worked( | ||
| self, conditions: dict = None, **kwargs | ||
|
||
| ) -> list: | ||
| event_ctx = self.create_event_context("read-many") | ||
| conditions.update({"owner_id": event_ctx.user_id}) | ||
| custom_query = self.build_custom_query( | ||
| is_admin=event_ctx.is_admin, | ||
| conditions=conditions, | ||
| ) | ||
| date_range = self.handle_date_filter_args(args=conditions) | ||
|
|
||
| project_dao = projects_model.create_dao() | ||
| projects = project_dao.get_all() | ||
| projects_ids = [project.id for project in projects] | ||
|
|
||
| activity_dao = activities_model.create_dao() | ||
| activities = activity_dao.get_all( | ||
| visible_only=False, | ||
| ) | ||
|
|
||
| result = [] | ||
| for id_project in projects_ids: | ||
| conditions.update({"project_id": id_project}) | ||
|
|
||
| limit = 2 | ||
|
||
| latest = self.repository.find_all_entries( | ||
| event_ctx, | ||
| conditions=conditions, | ||
| custom_sql_conditions=custom_query, | ||
| date_range=date_range, | ||
| max_count=limit, | ||
| ) | ||
|
||
|
|
||
| if len(latest) >= 1: | ||
|
||
| result.append(latest[0]) | ||
|
|
||
| add_activity_name_to_time_entries(result, activities) | ||
| add_project_info_to_time_entries(result, projects) | ||
|
|
||
| return result | ||
|
|
||
| def get_all_paginated(self, conditions: dict = None, **kwargs) -> list: | ||
| get_all_conditions = dict(conditions) | ||
| get_all_conditions.pop("length") | ||
| get_all_conditions.pop("start") | ||
| event_ctx = self.create_event_context("read-many") | ||
| get_all_conditions.update({"owner_id": event_ctx.user_id}) | ||
| custom_query = self.build_custom_query( | ||
| is_admin=event_ctx.is_admin, conditions=get_all_conditions, | ||
| is_admin=event_ctx.is_admin, | ||
| conditions=get_all_conditions, | ||
| ) | ||
| date_range = self.handle_date_filter_args(args=get_all_conditions) | ||
| records_total = self.repository.count( | ||
|
|
@@ -455,7 +501,8 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list: | |
| ) | ||
| conditions.update({"owner_id": event_ctx.user_id}) | ||
| custom_query = self.build_custom_query( | ||
| is_admin=event_ctx.is_admin, conditions=conditions, | ||
| is_admin=event_ctx.is_admin, | ||
| conditions=conditions, | ||
| ) | ||
| date_range = self.handle_date_filter_args(args=conditions) | ||
| length = conditions.get("length", None) | ||
|
|
@@ -499,7 +546,11 @@ def update(self, id, data: dict, description=None): | |
| time_entry = self.repository.find(id, event_ctx) | ||
| self.check_whether_current_user_owns_item(time_entry) | ||
|
|
||
| return self.repository.partial_update(id, data, event_ctx,) | ||
| return self.repository.partial_update( | ||
| id, | ||
| data, | ||
| event_ctx, | ||
| ) | ||
|
|
||
| def stop(self, id): | ||
| event_ctx = self.create_event_context("update", "Stop time entry") | ||
|
|
@@ -509,7 +560,9 @@ def stop(self, id): | |
| self.check_time_entry_is_not_stopped(time_entry) | ||
|
|
||
| return self.repository.partial_update( | ||
| id, {'end_date': current_datetime_str()}, event_ctx, | ||
| id, | ||
| {'end_date': current_datetime_str()}, | ||
| event_ctx, | ||
| ) | ||
|
|
||
| def restart(self, id): | ||
|
|
@@ -520,15 +573,18 @@ def restart(self, id): | |
| self.check_time_entry_is_not_started(time_entry) | ||
|
|
||
| return self.repository.partial_update( | ||
| id, {'end_date': None}, event_ctx, | ||
| id, | ||
| {'end_date': None}, | ||
| event_ctx, | ||
| ) | ||
|
|
||
| def delete(self, id): | ||
| event_ctx = self.create_event_context("delete") | ||
| time_entry = self.repository.find(id, event_ctx) | ||
| self.check_whether_current_user_owns_item(time_entry) | ||
| self.repository.delete( | ||
| id, event_ctx, | ||
| id, | ||
| event_ctx, | ||
| ) | ||
|
|
||
| def find_running(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,18 @@ def post(self): | |
| return time_entries_dao.create(ns.payload), HTTPStatus.CREATED | ||
|
|
||
|
|
||
|
Contributor
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. Can we add
Contributor
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. why exactly? should not we write proper tests instead of adding this?
Contributor
Author
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. @enriquezrene We put this TODO, in order to discuss in the next meeting. about the filters that we probably going to use in this endpoint
Contributor
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.
@enriquezrene in this part of the code, Paul copied functionality of another endpoint to make it work. It works fine as it , It only seems to me that there may be extra logic that could be avoided. For that reason, I wanted to add a reminder to review that later. We can enforce to remove that extra logic now or later, I am ok with both options.
Contributor
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. Lets do it now please |
||
| @ns.route('/latest') | ||
| class TimeEntries(Resource): | ||
|
||
| @ns.doc('list_latest_time_entries') | ||
| @ns.expect(attributes_filter) | ||
| @ns.marshal_list_with(time_entry) | ||
| @ns.response(HTTPStatus.NOT_FOUND, 'Time entry not found') | ||
| def get(self): | ||
| """List the latest time entries""" | ||
| conditions = attributes_filter.parse_args() | ||
| return time_entries_dao.get_last_projects_worked(conditions=conditions) | ||
|
|
||
|
|
||
| @ns.route('/<string:id>') | ||
| @ns.response(HTTPStatus.NOT_FOUND, 'This time entry does not exist') | ||
| @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want this function to be called something like :
get_latest_entriesorget_latest. I think get_last_project may be a bit misleading.