Skip to content

Commit

Permalink
Merge pull request #99 from developmentseed/catalogDependency
Browse files Browse the repository at this point in the history
add Catalog Dependency
  • Loading branch information
vincentsarago authored Jul 25, 2023
2 parents ef9aa7e + 99665c4 commit 2061bbc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
- `type` query parameter to filter collections based on their type (`Function` or `Table`)
- fixed a small bug in the `tipg_properties` SQL function where the bounds property was not properly transformed to 4326 (author @RemcoMeeuwissen, https://github.com/developmentseed/tipg/pull/87)
- added popups to leaflet maps on `items` and `item` page. (author @krishnaglodha & @jackharrhy, https://github.com/developmentseed/tipg/pull/91, https://github.com/developmentseed/tipg/pull/94)
- `catalog_dependency` to retrieve the list of collections (defaults to `tipg.dependencies.CatalogParams`)

### Changed

Expand Down
9 changes: 9 additions & 0 deletions tipg/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def CollectionParams(
)


def CatalogParams(request: Request) -> Catalog:
"""Return Collections Catalog."""
collection_catalog: Catalog = getattr(request.app.state, "collection_catalog", None)
if not collection_catalog:
raise MissingCollectionCatalog("Could not find collections catalog.")

return collection_catalog


def accept_media_type(
accept: str, mediatypes: List[enums.MediaType]
) -> Optional[enums.MediaType]:
Expand Down
16 changes: 4 additions & 12 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from tipg import model
from tipg.collections import Catalog, Collection
from tipg.dependencies import (
CatalogParams,
CollectionParams,
ItemsOutputType,
OutputType,
Expand All @@ -42,12 +43,7 @@
properties_query,
sortby_query,
)
from tipg.errors import (
MissingCollectionCatalog,
MissingGeometryColumn,
NoPrimaryKey,
NotFound,
)
from tipg.errors import MissingGeometryColumn, NoPrimaryKey, NotFound
from tipg.resources.enums import MediaType
from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse
from tipg.settings import FeaturesSettings, MVTSettings, TMSSettings
Expand Down Expand Up @@ -193,6 +189,7 @@ class EndpointsFactory(metaclass=abc.ABCMeta):
router: APIRouter = field(default_factory=APIRouter)

# collection dependency
catalog_dependency: Callable[..., Catalog] = CatalogParams
collection_dependency: Callable[..., Collection] = CollectionParams

# Router Prefix is needed to find the path for routes when prefixed
Expand Down Expand Up @@ -463,14 +460,9 @@ def collections( # noqa: C901
),
] = None,
output_type: Annotated[Optional[MediaType], Depends(OutputType)] = None,
collection_catalog=Depends(self.catalog_dependency),
):
"""List of collections."""
collection_catalog: Catalog = getattr(
request.app.state, "collection_catalog", None
)
if not collection_catalog:
raise MissingCollectionCatalog("Could not find collections catalog.")

collections_list = list(collection_catalog["collections"].values())

limit = limit or 0
Expand Down

0 comments on commit 2061bbc

Please sign in to comment.