Skip to content

Commit

Permalink
fix: task id on task polygon and feature extracts (hotosm#976)
Browse files Browse the repository at this point in the history
* feat: added qr code in task list

* added qr code in taskout schema

* feat: added task id on task polygon file

* feat: added task_id on features extracted file

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

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

* perf: prevent db call for each feat in task geojson

* refactor: typo task_id_mapping --> task_feature_mapping

---------

Co-authored-by: sujanadh <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: spwoodcock <[email protected]>
  • Loading branch information
4 people authored and nischalstha9 committed Dec 8, 2023
1 parent b82604e commit ffa5c44
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,12 @@ def get_task_geometry(db: Session, project_id: int):


async def get_project_features_geojson(db: Session, project_id: int):
db_features = (
db.query(db_models.DbFeatures)
.filter(db_models.DbFeatures.project_id == project_id)
.all()
)

"""Get a geojson of all features for a task."""
query = text(
f"""SELECT jsonb_build_object(
Expand All @@ -1711,6 +1717,14 @@ async def get_project_features_geojson(db: Session, project_id: int):

result = db.execute(query)
features = result.fetchone()[0]

# Create mapping feat_id:task_id
task_feature_mapping = {feat.id: feat.task_id for feat in db_features}

for feature in features["features"]:
if (feat_id := feature["id"]) in task_feature_mapping:
feature["properties"]["task_id"] = task_feature_mapping[feat_id]

return features


Expand Down

0 comments on commit ffa5c44

Please sign in to comment.