diff --git a/CHANGES.md b/CHANGES.md index f764efac..6c2cf124 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/tipg/factory.py b/tipg/factory.py index b829416e..021cf7b6 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -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.""" @@ -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", @@ -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, @@ -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, @@ -603,6 +613,7 @@ def collections( # noqa: C901 return data + def _collection_route(self): @self.router.get( "/collections/{collectionId}", response_model=model.Collection, @@ -688,6 +699,7 @@ def collection( return data + def _queryables_route(self): @self.router.get( "/collections/{collectionId}/queryables", response_model=model.Queryables, @@ -731,6 +743,7 @@ def queryables( return data + def _items_route(self): # noqa: C901 @self.router.get( "/collections/{collectionId}/items", response_class=GeoJSONResponse, @@ -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, @@ -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, @@ -1344,6 +1364,7 @@ async def tilematrixset( return data + def _tilesets_routes(self): @self.router.get( "/collections/{collectionId}/tiles", response_model=model.TileSetList, @@ -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, @@ -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) # ############################################################################ @@ -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,