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

split route registration to allow endpoint overriding #135

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
## [unreleased]

- hide map element in HTML pages when collections/items do not have spatial component
- split endpoints registration for more customization

## [0.4.4] - 2023-10-03

Expand Down
33 changes: 29 additions & 4 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ def __post_init__(self):
"""Post Init: register route and configure specific options."""
self.register_routes()
if self.with_common:
self.register_common_routes()
self._conformance_route()
self._landing_route()

def url_for(self, request: Request, name: str, **path_params: Any) -> str:
"""Return full url (with prefix) for a specific handler."""
Expand Down Expand Up @@ -269,8 +270,8 @@ def links(self, request: Request) -> List[model.Link]:
"""Register factory Routes."""
...

def register_common_routes(self):
"""Register Landing (/) and Conformance (/conformance) routes."""
def _conformance_route(self):
"""Register Conformance (/conformance) route."""

@self.router.get(
"/conformance",
Expand Down Expand Up @@ -303,6 +304,9 @@ def conformance(

return data

def _landing_route(self):
"""Register Landing (/) and Conformance (/conformance) routes."""

@self.router.get(
"/",
response_model=model.Landing,
Expand Down Expand Up @@ -421,9 +425,15 @@ def links(self, request: Request) -> List[model.Link]:
),
]

def register_routes(self): # noqa: C901
def register_routes(self):
"""Register OGC Features endpoints."""
self._collections_route()
self._collection_route()
self._queryables_route()
self._items_route()
self._item_route()

def _collections_route(self): # noqa: C901
@self.router.get(
"/collections",
response_model=model.Collections,
Expand Down Expand Up @@ -603,6 +613,7 @@ def collections( # noqa: C901

return data

def _collection_route(self):
@self.router.get(
"/collections/{collectionId}",
response_model=model.Collection,
Expand Down Expand Up @@ -688,6 +699,7 @@ def collection(

return data

def _queryables_route(self):
@self.router.get(
"/collections/{collectionId}/queryables",
response_model=model.Queryables,
Expand Down Expand Up @@ -731,6 +743,7 @@ def queryables(

return data

def _items_route(self): # noqa: C901
@self.router.get(
"/collections/{collectionId}/items",
response_class=GeoJSONResponse,
Expand Down Expand Up @@ -1005,6 +1018,7 @@ async def items( # noqa: C901
# Default to GeoJSON Response
return GeoJSONResponse(data)

def _item_route(self):
@self.router.get(
"/collections/{collectionId}/items/{itemId}",
response_class=GeoJSONResponse,
Expand Down Expand Up @@ -1247,7 +1261,13 @@ def links(self, request: Request) -> List[model.Link]:

def register_routes(self): # noqa: C901
"""Register OGC Tiles endpoints."""
self._tilematrixsets_routes()
self._tilesets_routes()
self._tile_routes()
self._tilejson_routes()
self._stylejson_routes()

def _tilematrixsets_routes(self):
@self.router.get(
r"/tileMatrixSets",
response_model=model.TileMatrixSetList,
Expand Down Expand Up @@ -1344,6 +1364,7 @@ async def tilematrixset(

return data

def _tilesets_routes(self):
@self.router.get(
"/collections/{collectionId}/tiles",
response_model=model.TileSetList,
Expand Down Expand Up @@ -1547,6 +1568,7 @@ async def collection_tileset(

return data

def _tile_routes(self):
@self.router.get(
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
response_class=Response,
Expand Down Expand Up @@ -1620,6 +1642,8 @@ async def collection_get_tile(

return Response(bytes(tile), media_type=MediaType.mvt.value)

def _tilejson_routes(self):

############################################################################
# ADDITIONAL ENDPOINTS NOT IN OGC Tiles API (tilejson, style.json, viewer) #
############################################################################
Expand Down Expand Up @@ -1721,6 +1745,7 @@ async def collection_tilejson(

return tile_json

def _stylejson_routes(self):
@self.router.get(
"/collections/{collectionId}/{tileMatrixSetId}/style.json",
response_model=model.StyleJSON,
Expand Down
Loading