Skip to content

Commit 83f779d

Browse files
committed
item collection tests
1 parent 6cbea93 commit 83f779d

File tree

5 files changed

+489
-232
lines changed

5 files changed

+489
-232
lines changed

stac_fastapi/core/stac_fastapi/core/extensions/catalogs.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Catalogs extension."""
22

3-
from typing import List, Type
3+
from typing import List, Optional, Type
44

55
import attr
66
from fastapi import APIRouter, FastAPI, HTTPException, Request
@@ -144,12 +144,18 @@ async def catalogs(self, request: Request) -> Catalog:
144144
# Create child links to each catalog
145145
child_links = []
146146
for catalog in catalogs:
147+
catalog_id = catalog.get("id") if isinstance(catalog, dict) else catalog.id
148+
catalog_title = (
149+
catalog.get("title") or catalog_id
150+
if isinstance(catalog, dict)
151+
else catalog.title or catalog.id
152+
)
147153
child_links.append(
148154
{
149155
"rel": "child",
150-
"href": f"{base_url}catalogs/{catalog.id}",
156+
"href": f"{base_url}catalogs/{catalog_id}",
151157
"type": "application/json",
152-
"title": catalog.title or catalog.id,
158+
"title": catalog_title,
153159
}
154160
)
155161

@@ -195,8 +201,12 @@ async def create_catalog(self, catalog: Catalog, request: Request) -> Catalog:
195201
# Convert STAC catalog to database format
196202
db_catalog = self.client.catalog_serializer.stac_to_db(catalog, request)
197203

198-
# Create the catalog in the database
199-
await self.client.database.create_catalog(db_catalog.model_dump())
204+
# Convert to dict and ensure type is set to Catalog
205+
db_catalog_dict = db_catalog.model_dump()
206+
db_catalog_dict["type"] = "Catalog"
207+
208+
# Create the catalog in the database with refresh to ensure immediate availability
209+
await self.client.database.create_catalog(db_catalog_dict, refresh=True)
200210

201211
# Return the created catalog
202212
return catalog
@@ -317,14 +327,35 @@ async def get_catalog_collection(
317327
)
318328

319329
async def get_catalog_collection_items(
320-
self, catalog_id: str, collection_id: str, request: Request
330+
self,
331+
catalog_id: str,
332+
collection_id: str,
333+
request: Request,
334+
bbox: Optional[List[float]] = None,
335+
datetime: Optional[str] = None,
336+
limit: Optional[int] = None,
337+
sortby: Optional[str] = None,
338+
filter_expr: Optional[str] = None,
339+
filter_lang: Optional[str] = None,
340+
token: Optional[str] = None,
341+
query: Optional[str] = None,
342+
fields: Optional[List[str]] = None,
321343
) -> stac_types.ItemCollection:
322344
"""Get items from a collection in a catalog.
323345
324346
Args:
325347
catalog_id: The ID of the catalog.
326348
collection_id: The ID of the collection.
327349
request: Request object.
350+
bbox: Optional bounding box filter.
351+
datetime: Optional datetime or interval filter.
352+
limit: Optional page size.
353+
sortby: Optional sort specification.
354+
filter_expr: Optional filter expression.
355+
filter_lang: Optional filter language.
356+
token: Optional pagination token.
357+
query: Optional query string.
358+
fields: Optional fields to include or exclude.
328359
329360
Returns:
330361
ItemCollection containing items from the collection.
@@ -337,9 +368,19 @@ async def get_catalog_collection_items(
337368
status_code=404, detail=f"Catalog {catalog_id} not found"
338369
)
339370

340-
# Delegate to the core client's item_collection method
371+
# Delegate to the core client's item_collection method with all parameters
341372
return await self.client.item_collection(
342-
collection_id=collection_id, request=request
373+
collection_id=collection_id,
374+
request=request,
375+
bbox=bbox,
376+
datetime=datetime,
377+
limit=limit,
378+
sortby=sortby,
379+
filter_expr=filter_expr,
380+
filter_lang=filter_lang,
381+
token=token,
382+
query=query,
383+
fields=fields,
343384
)
344385

345386
async def get_catalog_collection_item(

0 commit comments

Comments
 (0)