Skip to content

Commit

Permalink
fix: add uuid in read project and total_task in generate-log (#978)
Browse files Browse the repository at this point in the history
* feat: added uuid on read projects

* feat: added total task count in generate-log

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor: set uuid directly for project_uuid

---------

Co-authored-by: sujanadh <sujanadh07@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: spwoodcock <sam.woodcock@protonmail.com>
  • Loading branch information
4 people authored Nov 21, 2023
1 parent 319b115 commit 9281216
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2842,3 +2842,13 @@ def is_valid_coordinate(coord):
if not is_valid_coordinate(first_coordinate):
log.error(error_message)
raise HTTPException(status_code=400, detail=error_message)


def get_tasks_count(db: Session, project_id: int):
db_task = (
db.query(db_models.DbProject)
.filter(db_models.DbProject.id == project_id)
.first()
)
task_count = len(db_task.tasks)
return task_count
5 changes: 4 additions & 1 deletion src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ async def read_project_summaries(
async def read_project(project_id: int, db: Session = Depends(database.get_db)):
project = project_crud.get_project_by_id(db, project_id)
if project:
project.project_uuid = uuid.uuid4()
return project
else:
raise HTTPException(status_code=404, detail="Project not found")
Expand Down Expand Up @@ -222,8 +223,8 @@ async def create_project(
project = project_crud.create_project_with_project_info(
db, project_info, odkproject["id"]
)

if project:
project.project_uuid = uuid.uuid4()
return project
else:
raise HTTPException(status_code=404, detail="Project not found")
Expand Down Expand Up @@ -800,8 +801,10 @@ async def generate_log(
last_50_logs = filtered_logs[-50:]

logs = "\n".join(last_50_logs)
task_count = project_crud.get_tasks_count(db, project_id)
return {
"status": task_status.name,
"total_tasks": task_count,
"message": task_message,
"progress": extract_completion_count,
"logs": logs,
Expand Down
2 changes: 2 additions & 0 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#

import uuid
from typing import List, Optional, Union

from geojson_pydantic import Feature as GeojsonFeature
Expand Down Expand Up @@ -136,4 +137,5 @@ class ProjectBase(BaseModel):


class ProjectOut(ProjectBase):
project_uuid: uuid.UUID
pass

0 comments on commit 9281216

Please sign in to comment.