Skip to content

Commit

Permalink
fix(backend): including num_contribotors and total_tasks to the proje…
Browse files Browse the repository at this point in the history
…ct response
  • Loading branch information
spwoodcock committed Dec 9, 2024
1 parent 9b5c5d6 commit 6af9cdf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/backend/app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,13 @@ class DbProject(BaseModel):
Optional["ODKCentralDecrypted"],
Field(validate_default=True),
] = None
total_tasks: Optional[int] = None
num_contributors: Optional[int] = None
# FIXME we could add the following to the project summary cards
# Also required uncommenting of the ProjectSummary fields
# tasks_mapped: Optional[int] = 0
# tasks_validated: Optional[int] = 0
# tasks_bad: Optional[int] = 0

@field_validator("odk_credentials", mode="before")
@classmethod
Expand Down Expand Up @@ -1182,13 +1189,16 @@ async def all(
ST_AsGeoJSON(p.outline)::jsonb AS outline,
ST_AsGeoJSON(ST_Centroid(p.outline))::jsonb AS centroid,
project_org.logo as organisation_logo,
COUNT(t.id) AS task_count
COUNT(t.id) AS total_tasks,
COUNT(DISTINCT task_events.user_id) AS num_contributors
FROM
projects p
LEFT JOIN
organisations project_org ON p.organisation_id = project_org.id
LEFT JOIN
tasks t ON p.id = t.project_id
LEFT JOIN
task_events ON p.id = project_id
{'WHERE ' + ' AND '.join(filters) if filters else ''}
GROUP BY
p.id, project_org.id
Expand Down
16 changes: 9 additions & 7 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,21 @@ class ProjectSummary(BaseModel):
organisation_id: int
priority: ProjectPriority

outline: Optional[Polygon]
hashtags: Optional[list[str]]
location_str: Optional[str] = None
description: Optional[str] = None

# Calculated
outline: Optional[Polygon]
centroid: Optional[Point]
total_tasks: Optional[int] = None
num_contributors: Optional[int] = None
tasks_mapped: Optional[int] = None
tasks_validated: Optional[int] = None
tasks_bad: Optional[int] = None
organisation_logo: Optional[str] = None
centroid: Optional[Point]
total_tasks: Optional[int] = 0
num_contributors: Optional[int] = 0
# FIXME we could add the following to the project summary cards
# Also required uncommenting of the DbProject fields
# tasks_mapped: Optional[int] = 0
# tasks_validated: Optional[int] = 0
# tasks_bad: Optional[int] = 0


class PaginationInfo(BaseModel):
Expand Down

0 comments on commit 6af9cdf

Please sign in to comment.