Skip to content

Commit

Permalink
feat: create get api for project's geometry log
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujanadh committed Jan 15, 2025
1 parent ecda172 commit 4923233
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/backend/app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,25 @@ async def create(
new_geomlog = await cur.fetchone()
return new_geomlog

@classmethod
async def all(cls, db: Connection, project_id: int) -> Optional[list[Self]]:
"""Retrieve geometry logs from a project."""
async with db.cursor(row_factory=class_row(cls)) as cur:
await cur.execute(
"""
SELECT * FROM geometrylog WHERE project_id=%(project_id)s;
""",
{"project_id": project_id},
)
if cur.rowcount == 0:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND,
detail=f"""
No geometry log with project_id {project_id}
""",
)
return await cur.fetchall()

@classmethod
async def delete(
cls,
Expand Down
16 changes: 14 additions & 2 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,6 @@ async def update_project(

@router.post("/{project_id}/upload-task-boundaries")
async def upload_project_task_boundaries(
project_id: int,
db: Annotated[Connection, Depends(db_conn)],
project_user_dict: Annotated[ProjectUserDict, Depends(project_manager)],
task_geojson: UploadFile = File(...),
Expand All @@ -1084,6 +1083,7 @@ async def upload_project_task_boundaries(
Returns:
JSONResponse: JSON containing success message.
"""
project_id = project_user_dict.get("project").id
tasks_featcol = parse_geojson_file_to_featcol(await task_geojson.read())
await check_crs(tasks_featcol)
# We only want to allow polygon geometries
Expand Down Expand Up @@ -1241,7 +1241,6 @@ async def download_project_boundary(

@router.get("/{project_id}/download_tasks")
async def download_task_boundaries(
project_id: int,
db: Annotated[Connection, Depends(db_conn)],
project_user: Annotated[ProjectUserDict, Depends(mapper)],
):
Expand Down Expand Up @@ -1310,6 +1309,19 @@ async def create_geom_log(
return geometries


@router.get(
"{project_id}/geometries", response_model=list[project_schemas.GeometryLogIn]
)
async def read_geom_logs(
db: Annotated[Connection, Depends(db_conn)],
project_user: Annotated[ProjectUserDict, Depends(mapper)],
):
"""Retrieve geometry logs from a project."""
project_id = project_user.get("project").id
geometries = await DbGeometryLog.all(db, project_id)
return geometries


@router.delete("/{project_id}/geometries")
async def delete_geom_log(
geom_id: str,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse_input_geometry(
if value is None:
return None
featcol = geojson_to_featcol(value)
return featcol.get("features")[0].get("geometry")
return featcol.get("features")[0]


class ProjectInBase(DbProject):
Expand Down

0 comments on commit 4923233

Please sign in to comment.