@@ -52,31 +52,30 @@ class CoreClient(AsyncBaseCoreClient):
52
52
async def all_collections (self , ** kwargs ) -> Collections :
53
53
"""Read all collections from the database."""
54
54
base_url = str (kwargs ["request" ].base_url )
55
- collection_list = await self .database .get_all_collections ()
56
- collection_list = [
57
- self .collection_serializer .db_to_stac (c , base_url = base_url )
58
- for c in collection_list
59
- ]
60
-
61
- links = [
62
- {
63
- "rel" : Relations .root .value ,
64
- "type" : MimeTypes .json ,
65
- "href" : base_url ,
66
- },
67
- {
68
- "rel" : Relations .parent .value ,
69
- "type" : MimeTypes .json ,
70
- "href" : base_url ,
71
- },
72
- {
73
- "rel" : Relations .self .value ,
74
- "type" : MimeTypes .json ,
75
- "href" : urljoin (base_url , "collections" ),
76
- },
77
- ]
78
55
79
- return Collections (collections = collection_list , links = links )
56
+ return Collections (
57
+ collections = [
58
+ self .collection_serializer .db_to_stac (c , base_url = base_url )
59
+ for c in await self .database .get_all_collections ()
60
+ ],
61
+ links = [
62
+ {
63
+ "rel" : Relations .root .value ,
64
+ "type" : MimeTypes .json ,
65
+ "href" : base_url ,
66
+ },
67
+ {
68
+ "rel" : Relations .parent .value ,
69
+ "type" : MimeTypes .json ,
70
+ "href" : base_url ,
71
+ },
72
+ {
73
+ "rel" : Relations .self .value ,
74
+ "type" : MimeTypes .json ,
75
+ "href" : urljoin (base_url , "collections" ),
76
+ },
77
+ ],
78
+ )
80
79
81
80
@overrides
82
81
async def get_collection (self , collection_id : str , ** kwargs ) -> Collection :
@@ -100,6 +99,8 @@ async def item_collection(
100
99
limit = limit ,
101
100
token = token ,
102
101
sort = None ,
102
+ collection_ids = [collection_id ],
103
+ ignore_unavailable = False ,
103
104
)
104
105
105
106
items = [
@@ -276,6 +277,7 @@ async def post_search(
276
277
limit = limit ,
277
278
token = search_request .token , # type: ignore
278
279
sort = sort ,
280
+ collection_ids = search_request .collections ,
279
281
)
280
282
281
283
items = [
@@ -341,8 +343,11 @@ async def create_item(self, item: stac_types.Item, **kwargs) -> stac_types.Item:
341
343
processed_items = [
342
344
bulk_client .preprocess_item (item , base_url ) for item in item ["features" ] # type: ignore
343
345
]
346
+
347
+ # not a great way to get the collection_id-- should be part of the method signature
348
+ collection_id = processed_items [0 ]["collection" ]
344
349
await self .database .bulk_async (
345
- processed_items , refresh = kwargs .get ("refresh" , False )
350
+ collection_id , processed_items , refresh = kwargs .get ("refresh" , False )
346
351
)
347
352
348
353
return None # type: ignore
@@ -355,12 +360,14 @@ async def create_item(self, item: stac_types.Item, **kwargs) -> stac_types.Item:
355
360
async def update_item (self , item : stac_types .Item , ** kwargs ) -> stac_types .Item :
356
361
"""Update item."""
357
362
base_url = str (kwargs ["request" ].base_url )
363
+ collection_id = item ["collection" ]
364
+
358
365
now = datetime_type .now (timezone .utc ).isoformat ().replace ("+00:00" , "Z" )
359
366
item ["properties" ]["updated" ] = str (now )
360
367
361
- await self .database .check_collection_exists (collection_id = item [ "collection" ] )
368
+ await self .database .check_collection_exists (collection_id )
362
369
# todo: index instead of delete and create
363
- await self .delete_item (item_id = item ["id" ], collection_id = item [ "collection" ] )
370
+ await self .delete_item (item_id = item ["id" ], collection_id = collection_id )
364
371
await self .create_item (item = item , ** kwargs )
365
372
366
373
return ItemSerializer .db_to_stac (item , base_url )
@@ -440,6 +447,11 @@ def bulk_item_insert(
440
447
self .preprocess_item (item , base_url ) for item in items .items .values ()
441
448
]
442
449
443
- self .database .bulk_sync (processed_items , refresh = kwargs .get ("refresh" , False ))
450
+ # not a great way to get the collection_id-- should be part of the method signature
451
+ collection_id = processed_items [0 ]["collection" ]
452
+
453
+ self .database .bulk_sync (
454
+ collection_id , processed_items , refresh = kwargs .get ("refresh" , False )
455
+ )
444
456
445
457
return f"Successfully added { len (processed_items )} Items."
0 commit comments