From 2707a21263f5f0b42c21396fba6dd049a8f9b48f Mon Sep 17 00:00:00 2001 From: Daniel Mannarino Date: Thu, 16 Jan 2025 22:37:04 -0500 Subject: [PATCH] Improve RWAdminListResponse to omit missing name attribute --- app/models/pydantic/geostore.py | 9 +++++++-- app/routes/geostore/geostore.py | 7 ++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/models/pydantic/geostore.py b/app/models/pydantic/geostore.py index 59c3c0be..6ef6ae55 100644 --- a/app/models/pydantic/geostore.py +++ b/app/models/pydantic/geostore.py @@ -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): diff --git a/app/routes/geostore/geostore.py b/app/routes/geostore/geostore.py index c3edec51..fc1562a6 100644 --- a/app/routes/geostore/geostore.py +++ b/app/routes/geostore/geostore.py @@ -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 @@ -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