Skip to content

add Catalog Dependency #99

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

Merged
merged 1 commit into from
Jul 25, 2023
Merged
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
@@ -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

9 changes: 9 additions & 0 deletions tipg/dependencies.py
Original file line number Diff line number Diff line change
@@ -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]:
16 changes: 4 additions & 12 deletions tipg/factory.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
from tipg import model
from tipg.collections import Catalog, Collection
from tipg.dependencies import (
CatalogParams,
CollectionParams,
ItemsOutputType,
OutputType,
@@ -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
@@ -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
@@ -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