Skip to content

Commit

Permalink
Improve RWAdminListResponse to omit missing name attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dmannarino committed Jan 17, 2025
1 parent af18197 commit 2707a21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 7 additions & 2 deletions app/models/pydantic/geostore.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ class WDPAInfo(StrictBaseModel):
class RWAdminListItem(StrictBaseModel):
geostoreId: str
iso: str
name: Optional[str]
name: str


class RWAdminListItemWithName(StrictBaseModel):
geostoreId: str
iso: str


class RWAdminListResponse(StrictBaseModel):
data: List[RWAdminListItem]
data: List[RWAdminListItem | RWAdminListItemWithName]


class RWGeostoreAttributes(StrictBaseModel):
Expand Down
7 changes: 2 additions & 5 deletions app/routes/geostore/geostore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Retrieve a geometry using its md5 hash for a given dataset, user defined
geometries in the datastore."""
from typing import Annotated, Dict
from uuid import UUID

from fastapi import APIRouter, Header, HTTPException, Path
from fastapi.responses import ORJSONResponse
Expand Down Expand Up @@ -103,14 +102,12 @@ async def get_any_geostore(
# If provided geostore ID follows UUID4 style, it's meant for GFW Data API
if isinstance(geostore_id, UUID4):
try:
result: Geostore = await geostore.get_gfw_geostore_from_any_dataset(
geostore_id
)
result = await geostore.get_gfw_geostore_from_any_dataset(geostore_id)
return GeostoreResponse(data=result)
except RecordNotFoundError as e:
raise HTTPException(status_code=404, detail=str(e))
# Otherwise, forward to RW geostore
result: RWGeostoreResponse = await proxy_get_geostore(geostore_id, x_api_key)
result = await proxy_get_geostore(geostore_id, x_api_key)
return result


Expand Down

0 comments on commit 2707a21

Please sign in to comment.