Skip to content

Commit

Permalink
feat(backend): return entity uuid on create (#2151)
Browse files Browse the repository at this point in the history
* fix: allow users to select default odk credentials

* fix: return response of entity creation in order to use entity id

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

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Sujanadh and pre-commit-ci[bot] authored Feb 5, 2025
1 parent 887813b commit f734fb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ async def create_entity(
properties: list[str],
entity: central_schemas.EntityDict,
dataset_name: str = "features",
) -> None:
) -> dict:
"""Create a new Entity in ODK."""
log.info(f"Creating ODK Entity in dataset '{dataset_name}' (ODK ID: {odk_id})")
try:
Expand All @@ -613,8 +613,9 @@ async def create_entity(
raise ValueError("Entity must contain 'label' and 'data' fields")

async with central_deps.get_odk_dataset(odk_creds) as odk_central:
await odk_central.createEntity(odk_id, dataset_name, label, data)
response = await odk_central.createEntity(odk_id, dataset_name, label, data)
log.info(f"Entity '{label}' successfully created in ODK")
return response

except Exception as e:
log.exception(f"Failed to create entity in ODK: {str(e)}")
Expand Down
3 changes: 1 addition & 2 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,15 +917,14 @@ async def add_new_entity(
)

# Create entity in ODK
await central_crud.create_entity(
return await central_crud.create_entity(
project_odk_creds,
project_odk_id,
properties=properties,
entity=entities_list[0],
dataset_name="features",
)

return Response(status_code=HTTPStatus.OK)
except HTTPException as http_err:
log.error(f"HTTP error: {http_err.detail}")
raise
Expand Down

0 comments on commit f734fb9

Please sign in to comment.