Skip to content

Commit

Permalink
Added field total when getting paginated tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
c8y3 committed Jan 24, 2025
1 parent edd8549 commit ca52ca7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
7 changes: 4 additions & 3 deletions source/app/blueprints/rest/v2/cases/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from app.business.tasks import tasks_update
from app.business.tasks import tasks_delete
# TODO should rather go to the business layer here, rather than directly down into the persistence layer
from app.datamgmt.case.case_tasks_db import get_tasks
from app.datamgmt.case.case_tasks_db import get_filtered_tasks
from app.models.authorization import CaseAccessLevel
from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access

Expand Down Expand Up @@ -69,10 +69,11 @@ def case_get_tasks(case_identifier):
if not ac_fast_check_current_user_has_case_access(case_identifier, [CaseAccessLevel.read_only, CaseAccessLevel.full_access]):
return ac_api_return_access_denied(caseid=case_identifier)

tasks = get_tasks(case_identifier)
tasks = get_filtered_tasks(case_identifier)

result = {
'data': tasks
'total': tasks.total,
'data': tasks.items
}

return response_api_success(result)
Expand Down
18 changes: 12 additions & 6 deletions source/app/datamgmt/case/case_tasks_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ def get_tasks_status():
return TaskStatus.query.all()


def get_tasks(caseid):
return CaseTasks.query.with_entities(
def get_filtered_tasks(caseid, page=1, per_page=100):
return CaseTasks.query.filter(
CaseTasks.task_case_id == caseid
).join(
CaseTasks.status
).order_by(
desc(TaskStatus.status_name)
).paginate(page=page, per_page=per_page, error_out=False)


def get_tasks_with_assignees(caseid):
tasks = CaseTasks.query.with_entities(
CaseTasks.id.label('task_id'),
CaseTasks.task_uuid,
CaseTasks.task_title,
Expand All @@ -56,10 +66,6 @@ def get_tasks(caseid):
).order_by(
desc(TaskStatus.status_name)
).all()


def get_tasks_with_assignees(caseid):
tasks = get_tasks(caseid)
if not tasks:
return None

Expand Down
9 changes: 8 additions & 1 deletion tests/tests_rest_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,11 @@ def test_get_tasks_should_return_200(self):
def test_get_tasks_should_return_empty_list_for_field_data_when_there_are_no_tasks(self):
case_identifier = self._subject.create_dummy_case()
response = self._subject.get(f'/api/v2/cases/{case_identifier}/tasks').json()
self.assertEqual([], response['data'])
self.assertEqual([], response['data'])

def test_get_tasks_should_return_total(self):
case_identifier = self._subject.create_dummy_case()
body = {'task_assignees_id': [], 'task_status_id': 1, 'task_title': 'dummy title'}
self._subject.create(f'/api/v2/cases/{case_identifier}/tasks', body).json()
response = self._subject.get(f'/api/v2/cases/{case_identifier}/tasks').json()
self.assertEqual(1, response['total'])

0 comments on commit ca52ca7

Please sign in to comment.