Skip to content

Commit

Permalink
fix: simplify response when getting project features
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 25, 2023
1 parent 3c3236d commit 0ca2de2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
25 changes: 24 additions & 1 deletion src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ def split_polygon_into_tasks(
db.add(db_task)
db.commit()

# Get the data extract from raw-data-api
# Input into DbBuildings and DbOsmLines
# TODO update to use flatgeobuf file directly
# No need to store in our database
if not has_data_extracts:
data = get_osm_extracts(json.dumps(boundary_data))
if not data:
Expand Down Expand Up @@ -1655,7 +1659,7 @@ def get_task_geometry(db: Session, project_id: int):


async def get_project_features_geojson(db: Session, project_id: int):
# Get the geojson of those features for this task.
"""Get a geojson of all features for a task."""
query = text(
f"""SELECT jsonb_build_object(
'type', 'FeatureCollection',
Expand All @@ -1676,6 +1680,25 @@ async def get_project_features_geojson(db: Session, project_id: int):

result = db.execute(query)
features = result.fetchone()[0]
# Simplify the geojson to send (strip project_id & task_id to reduce size)
# TODO coordinate with frontend to remove the first level geometry key
# Only return geojson with properties:
# {'type': 'feature', 'geometry': {...}, 'properties': {...}}
features = [
{
"id": feature["id"],
"geometry": {
"id": feature["geometry"]["id"],
"type": feature["geometry"]["type"],
"geometry": feature["geometry"]["geometry"],
"properties": {
"id": feature["geometry"]["properties"]["id"],
"building": feature["geometry"]["properties"]["building"],
},
},
}
for feature in features
]
return features


Expand Down
14 changes: 7 additions & 7 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,16 +673,16 @@ def get_project_features(
task_id: int = None,
db: Session = Depends(database.get_db),
):
"""Get api for fetching all the features of a project.
"""Fetch all the features for a project.
This endpoint allows you to get all the features of a project.
The features are generated from raw-data-api
## Request Body
- `project_id` (int): the project's id. Required.
## Response
- Returns a JSON object containing a list of features.
Args:
project_id (int): The project id.
task_id (int): The task id.
Returns:
feature(json): JSON object containing a list of features
"""
features = project_crud.get_project_features(db, project_id, task_id)
return features
Expand Down

0 comments on commit 0ca2de2

Please sign in to comment.