Skip to content

Commit dd44d6f

Browse files
committed
split route registration to allow endpoint overriding
1 parent 11b4411 commit dd44d6f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
99
## [unreleased]
1010

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

1314
## [0.4.4] - 2023-10-03
1415

tipg/factory.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,15 @@ def links(self, request: Request) -> List[model.Link]:
421421
),
422422
]
423423

424-
def register_routes(self): # noqa: C901
424+
def register_routes(self):
425425
"""Register OGC Features endpoints."""
426+
self._collections_route()
427+
self._collection_route()
428+
self._queryables_route()
429+
self._items_route()
430+
self._item_route()
426431

432+
def _collections_route(self): # noqa: C901
427433
@self.router.get(
428434
"/collections",
429435
response_model=model.Collections,
@@ -603,6 +609,7 @@ def collections( # noqa: C901
603609

604610
return data
605611

612+
def _collection_route(self):
606613
@self.router.get(
607614
"/collections/{collectionId}",
608615
response_model=model.Collection,
@@ -688,6 +695,7 @@ def collection(
688695

689696
return data
690697

698+
def _queryables_route(self):
691699
@self.router.get(
692700
"/collections/{collectionId}/queryables",
693701
response_model=model.Queryables,
@@ -731,6 +739,7 @@ def queryables(
731739

732740
return data
733741

742+
def _items_route(self): # noqa: C901
734743
@self.router.get(
735744
"/collections/{collectionId}/items",
736745
response_class=GeoJSONResponse,
@@ -1005,6 +1014,7 @@ async def items( # noqa: C901
10051014
# Default to GeoJSON Response
10061015
return GeoJSONResponse(data)
10071016

1017+
def _item_route(self):
10081018
@self.router.get(
10091019
"/collections/{collectionId}/items/{itemId}",
10101020
response_class=GeoJSONResponse,
@@ -1247,7 +1257,13 @@ def links(self, request: Request) -> List[model.Link]:
12471257

12481258
def register_routes(self): # noqa: C901
12491259
"""Register OGC Tiles endpoints."""
1260+
self._tilematrixsets_routes()
1261+
self._tilesets_routes()
1262+
self._tile_routes()
1263+
self._tilejson_routes()
1264+
self._stylejson_routes()
12501265

1266+
def _tilematrixsets_routes(self):
12511267
@self.router.get(
12521268
r"/tileMatrixSets",
12531269
response_model=model.TileMatrixSetList,
@@ -1344,6 +1360,7 @@ async def tilematrixset(
13441360

13451361
return data
13461362

1363+
def _tilesets_routes(self):
13471364
@self.router.get(
13481365
"/collections/{collectionId}/tiles",
13491366
response_model=model.TileSetList,
@@ -1547,6 +1564,7 @@ async def collection_tileset(
15471564

15481565
return data
15491566

1567+
def _tile_routes(self):
15501568
@self.router.get(
15511569
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
15521570
response_class=Response,
@@ -1620,6 +1638,8 @@ async def collection_get_tile(
16201638

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

1641+
def _tilejson_routes(self):
1642+
16231643
############################################################################
16241644
# ADDITIONAL ENDPOINTS NOT IN OGC Tiles API (tilejson, style.json, viewer) #
16251645
############################################################################
@@ -1721,6 +1741,7 @@ async def collection_tilejson(
17211741

17221742
return tile_json
17231743

1744+
def _stylejson_routes(self):
17241745
@self.router.get(
17251746
"/collections/{collectionId}/{tileMatrixSetId}/style.json",
17261747
response_model=model.StyleJSON,

0 commit comments

Comments
 (0)