Skip to content

Commit

Permalink
fix: use task index instead of id in task boundary geojson properties (
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujanadh authored Jan 20, 2025
1 parent 274bc18 commit 75b8e16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
32 changes: 21 additions & 11 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from app.central import central_crud, central_schemas
from app.config import settings
from app.db.enums import BackgroundTaskStatus, HTTPStatus, XLSFormType
from app.db.models import DbBackgroundTask, DbBasemap, DbProject, DbTask, DbUser
from app.db.models import DbBackgroundTask, DbBasemap, DbProject, DbUser
from app.db.postgis_utils import (
check_crs,
featcol_keep_single_geom_type,
Expand Down Expand Up @@ -623,18 +623,28 @@ async def get_task_geometry(db: Connection, project_id: int):
Returns:
str: A geojson of the task boundaries
"""
db_tasks = await DbTask.all(db, project_id)
features = []
for task in db_tasks:
properties = {
"task_id": task.id,
}
feature = {
query = """
SELECT project_task_index,
ST_AsGeoJSON(tasks.outline)::jsonb AS outline
FROM tasks
WHERE project_id = %(project_id)s
"""
async with db.cursor(row_factory=class_row(dict)) as cur:
await cur.execute(query, {"project_id": project_id})
db_tasks = await cur.fetchall()

if not db_tasks:
raise ValueError(f"No tasks found for project ID {project_id}.")

features = [
{
"type": "Feature",
"geometry": task.outline,
"properties": properties,
"geometry": task["outline"],
"properties": {"task_id": task["project_task_index"]},
}
features.append(feature)
for task in db_tasks
if task["outline"] # Exclude tasks with no geometry
]

feature_collection = {"type": "FeatureCollection", "features": features}
return json.dumps(feature_collection)
Expand Down
6 changes: 3 additions & 3 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,14 @@ async def download_task_boundaries(
Response: The HTTP response object containing the downloaded file.
"""
project_id = project_user.get("project").id
out = await project_crud.get_task_geometry(db, project_id)
task_geojson = await project_crud.get_task_geometry(db, project_id)

headers = {
"Content-Disposition": "attachment; filename=project_outline.geojson",
"Content-Disposition": "attachment; filename=task_boundary.geojson",
"Content-Type": "application/media",
}

return Response(content=out, headers=headers)
return Response(content=task_geojson, headers=headers)


@router.post("/{project_id}/geometry/records")
Expand Down

0 comments on commit 75b8e16

Please sign in to comment.