|
5 | 5 | from datetime import datetime as datetime_type |
6 | 6 | from datetime import timezone |
7 | 7 | from enum import Enum |
8 | | -from types import SimpleNamespace |
9 | 8 | from typing import List, Optional, Set, Type, Union |
10 | 9 | from urllib.parse import unquote_plus, urljoin |
11 | 10 |
|
@@ -311,71 +310,15 @@ async def item_collection( |
311 | 310 | Exception: If any error occurs while reading the items from the database. |
312 | 311 | """ |
313 | 312 | 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]] |
354 | 313 |
|
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, |
360 | 319 | limit=limit, |
361 | | - sort=es_sort, |
362 | 320 | 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, |
379 | 322 | ) |
380 | 323 |
|
381 | 324 | async def get_item( |
|
0 commit comments