Skip to content

Commit 8c6742f

Browse files
committed
pass item collection to get search
1 parent d19c855 commit 8c6742f

File tree

1 file changed

+6
-63
lines changed
  • stac_fastapi/core/stac_fastapi/core

1 file changed

+6
-63
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import datetime as datetime_type
66
from datetime import timezone
77
from enum import Enum
8-
from types import SimpleNamespace
98
from typing import List, Optional, Set, Type, Union
109
from urllib.parse import unquote_plus, urljoin
1110

@@ -311,71 +310,15 @@ async def item_collection(
311310
Exception: If any error occurs while reading the items from the database.
312311
"""
313312
request: Request = kwargs["request"]
314-
token = request.query_params.get("token")
315-
316-
base_url = str(request.base_url)
317-
318-
es_sort = None
319-
if sortby:
320-
specs = []
321-
for s in sortby:
322-
field = s[1:]
323-
direction = "desc" if s[0] == "-" else "asc"
324-
specs.append(SimpleNamespace(field=field, direction=direction))
325-
if specs:
326-
es_sort = self.database.populate_sort(specs)
327-
328-
collection = await self.get_collection(
329-
collection_id=collection_id, request=request
330-
)
331-
collection_id = collection.get("id")
332-
if collection_id is None:
333-
raise HTTPException(status_code=404, detail="Collection not found")
334-
335-
search = self.database.make_search()
336-
search = self.database.apply_collections_filter(
337-
search=search, collection_ids=[collection_id]
338-
)
339-
340-
try:
341-
search, datetime_search = self.database.apply_datetime_filter(
342-
search=search, datetime=datetime
343-
)
344-
except (ValueError, TypeError) as e:
345-
# Handle invalid interval formats if return_date fails
346-
msg = f"Invalid interval format: {datetime}, error: {e}"
347-
logger.error(msg)
348-
raise HTTPException(status_code=400, detail=msg)
349-
350-
if bbox:
351-
bbox = [float(x) for x in bbox]
352-
if len(bbox) == 6:
353-
bbox = [bbox[0], bbox[1], bbox[3], bbox[4]]
354313

355-
search = self.database.apply_bbox_filter(search=search, bbox=bbox)
356-
357-
limit = int(request.query_params.get("limit", os.getenv("STAC_ITEM_LIMIT", 10)))
358-
items, maybe_count, next_token = await self.database.execute_search(
359-
search=search,
314+
return await self.get_search(
315+
request=request,
316+
collections=[collection_id],
317+
bbox=bbox,
318+
datetime=datetime,
360319
limit=limit,
361-
sort=es_sort,
362320
token=token,
363-
collection_ids=[collection_id],
364-
datetime_search=datetime_search,
365-
)
366-
367-
items = [
368-
self.item_serializer.db_to_stac(item, base_url=base_url) for item in items
369-
]
370-
371-
links = await PagingLinks(request=request, next=next_token).get_links()
372-
373-
return stac_types.ItemCollection(
374-
type="FeatureCollection",
375-
features=items,
376-
links=links,
377-
numReturned=len(items),
378-
numMatched=maybe_count,
321+
sortby=sortby,
379322
)
380323

381324
async def get_item(

0 commit comments

Comments
 (0)