Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTC-3084: Add new endpoints that proxy to geostore microservice (for now) #621

Draft
wants to merge 29 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
99a0ce0
Bump deps to allow building
dmannarino Jan 1, 2025
511ad16
Proxy the first two RW API requests
dmannarino Jan 6, 2025
912121c
Only Pydantic models suitable as route return values
dmannarino Jan 6, 2025
c54cd43
More routes
dmannarino Jan 7, 2025
11d35e2
Add endpoint to proxy to RW for getting geostores by land use and index
dmannarino Jan 7, 2025
1248f79
Fix a typo; add proxy route to get a geostore by wdpa_id
dmannarino Jan 7, 2025
250a865
Add RW endpoint to get a view link for a geostore by id
dmannarino Jan 7, 2025
5484f69
Add proxy to RW route to find geostores by ids
dmannarino Jan 7, 2025
6154d1a
Add proxy to RW endpoint calculating geostore area
dmannarino Jan 7, 2025
361f425
For geostore by wpaid: Run through (new) Pydantic models; pass along …
dmannarino Jan 8, 2025
e0fa91b
Fix broken imports and bbox type declaration
dmannarino Jan 8, 2025
3cb3afd
Fix loading of RW response
dmannarino Jan 8, 2025
a3b8bb4
Add missing geojson attribute to RWGeostoreAttributes
dmannarino Jan 8, 2025
c09c20a
WIP: Add initial RW proxy tests (1 passes, 1 fails)
dmannarino Jan 14, 2025
ae3fb51
WIP: Comment-out failing test for the moment in order to get to deploy
dmannarino Jan 14, 2025
490d02e
Fix RW geostore-by-land-use proxy; rearrange RW response models to re…
dmannarino Jan 14, 2025
67299e4
Fix up RW geostore boundary proxy functions
dmannarino Jan 14, 2025
41526af
Fix RW proxy to admin list endpoint, add models
dmannarino Jan 16, 2025
bbe82e4
Fix RW proxy for get_view_geostore_by_id endpoint; linting
dmannarino Jan 16, 2025
5c0ab0b
Fix RW proxied geostore calc area endpoint
dmannarino Jan 16, 2025
1c2ae72
Fix RW proxied geostore find-by-ids endpoint
dmannarino Jan 16, 2025
5cd5e08
Make name optional for RWAdminListItem
dmannarino Jan 16, 2025
8e63c8c
Fix copy pasta mistake for find_by_ids
dmannarino Jan 16, 2025
6dff707
Fix dropping payload and post->get in find-by-ids, calc area function…
dmannarino Jan 17, 2025
af18197
Fix URL for create_rw_geostore; implement proxy to RW get geostore en…
dmannarino Jan 17, 2025
2707a21
Improve RWAdminListResponse to omit missing name attribute
dmannarino Jan 17, 2025
a1da0c0
Fix detection of UUID param
dmannarino Jan 17, 2025
be7b8e3
Remove unnecessary parameter
dmannarino Jan 17, 2025
b2ad219
Cleanup
dmannarino Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ google-cloud-storage = "*"
httpcore = "*"
httpx = "*"
httpx-auth = "*"
numpy = "<2.0"
numpy = "*"
orjson = "*"
packaging = "*"
pendulum = "<3"
Expand Down
4,534 changes: 2,318 additions & 2,216 deletions Pipfile.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions app/models/enum/geostore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@
class GeostoreOrigin(str, Enum):
gfw = "gfw"
rw = "rw"


class LandUseType(str, Enum):
fiber = "fiber"
logging = "logging"
mining = "mining"
oil_palm = "oil_palm"
tiger_conservation_landscapes = "tiger_conservation_landscapes"


class LandUseTypeUseString(str, Enum):
fiber = "fiber"
logging = "gfw_logging"
mining = "mining"
oil_palm = "oil_palm"
tiger_conservation_landscapes = "tiger_conservation_landscapes"
134 changes: 132 additions & 2 deletions app/models/pydantic/geostore.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Literal, Optional
from uuid import UUID

from pydantic import validator

from ..enum.geostore import LandUseTypeUseString
from .base import BaseRecord, StrictBaseModel
from .responses import Response

Expand All @@ -14,7 +15,7 @@ class Geometry(StrictBaseModel):


class Feature(StrictBaseModel):
properties: Dict[str, Any]
properties: Optional[Dict[str, Any]]
type: str
geometry: Optional[Geometry]

Expand Down Expand Up @@ -50,5 +51,134 @@ class GeostoreIn(StrictBaseModel):
geometry: Geometry


class RWGeostoreIn(StrictBaseModel):
geojson: Geometry | Feature | FeatureCollection


class GeostoreResponse(Response):
data: Geostore


class RWCalcAreaForGeostoreIn(StrictBaseModel):
properties: Dict
type: str
geometry: Geometry


class RWCalcAreaForGeostoreAttributes(StrictBaseModel):
bbox: List[float]
areaHA: float


class RWCalcAreaForGeostoreData(StrictBaseModel):
type: Literal["geomArea"]
attributes: RWCalcAreaForGeostoreAttributes


class RWCalcAreaForGeostoreResponse(StrictBaseModel):
data: RWCalcAreaForGeostoreData


class RWFindByIDsIn(StrictBaseModel):
geostores: List[str]


class RWViewGeostoreResponse(StrictBaseModel):
view_link: str


class AdminBoundaryInfo(StrictBaseModel):
use: Dict
simplifyThresh: float
gadm: str # TODO: Make an enum?
name: str
id2: int
id1: int
iso: str


class CreateGeostoreResponseInfo(StrictBaseModel):
use: Dict


class FindByIDsInfo(StrictBaseModel):
use: Dict
iso: str
name: str


class LandUseUse(StrictBaseModel):
use: LandUseTypeUseString
id: int


class LandUseInfo(StrictBaseModel):
use: LandUseUse
simplify: bool


class WDPAInfo(StrictBaseModel):
use: Dict
wdpaid: int


class RWAdminListItem(StrictBaseModel):
geostoreId: str
iso: str
name: str


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


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


class RWGeostoreAttributes(StrictBaseModel):
geojson: FeatureCollection
hash: str
provider: Dict
areaHa: float
bbox: List[float]
lock: bool
info: AdminBoundaryInfo | CreateGeostoreResponseInfo | FindByIDsInfo | LandUseInfo | WDPAInfo


class RWGeostore(StrictBaseModel):
type: Literal["geoStore"]
id: str
attributes: RWGeostoreAttributes


class RWGeostoreResponse(StrictBaseModel):
data: RWGeostore


class RWFindByIDsGeostoreData(StrictBaseModel):
type: Literal["geoStore"]
id: str
attributes: RWGeostoreAttributes


class RWFindByIDsDataGeostore(StrictBaseModel):
data: RWFindByIDsGeostoreData


class RWFindByIDsData(StrictBaseModel):
geostoreId: str
geostore: RWFindByIDsGeostoreData
returned: int


class RWFindByIDsInfo(StrictBaseModel):
found: int
foundIDs: List[str]
returned: int


class RWFindByIDsResponse(StrictBaseModel):
data: List[RWFindByIDsData]
info: RWFindByIDsInfo
Loading
Loading