From 40619b4b417f2ce1d26fb0abbfcb806a9f0e8b08 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari <41701707+nrjadkry@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:36:09 +0545 Subject: [PATCH] fix: feature count in task features count api (#904) * fix: feature count in task features count api * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * task_count passed in the upload multipolygon api * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/backend/app/projects/project_routes.py | 9 ++++++++- src/backend/app/tasks/tasks_routes.py | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index ce7d2d8b82..f93cf2edcd 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -378,7 +378,14 @@ async def upload_multi_project_boundary( status_code=428, detail=f"Project with id {project_id} does not exist" ) - return {"message": "Project Boundary Uploaded", "project_id": f"{project_id}"} + # Get the number of tasks in a project + task_count = await tasks_crud.get_task_count_in_project(db, project_id) + + return { + "message": "Project Boundary Uploaded", + "project_id": f"{project_id}", + "task_count": task_count, + } @router.post("/task_split") diff --git a/src/backend/app/tasks/tasks_routes.py b/src/backend/app/tasks/tasks_routes.py index 92386da921..e45883b68a 100644 --- a/src/backend/app/tasks/tasks_routes.py +++ b/src/backend/app/tasks/tasks_routes.py @@ -172,9 +172,11 @@ async def task_features_count( # Assemble the final data list data = [] for x in odk_details: - feature_count_query = f""" + feature_count_query = text( + f""" select count(*) from features where project_id = {project_id} and task_id = {x['xmlFormId']} """ + ) result = db.execute(feature_count_query) feature_count = result.fetchone() @@ -184,7 +186,7 @@ async def task_features_count( "task_id": x["xmlFormId"], "submission_count": x["submissions"], "last_submission": x["lastSubmission"], - "feature_count": feature_count["count"], + "feature_count": feature_count[0], } )