diff --git a/dlx_rest/models.py b/dlx_rest/models.py index 53b7cd1f..e772b465 100644 --- a/dlx_rest/models.py +++ b/dlx_rest/models.py @@ -161,10 +161,13 @@ def get_item_by_id(self, item_id): return this_item def get_item_by_coll_and_rid(self, collection, record_id): - return list(filter(lambda x: x['record_id'] == record_id and x['collection'] == collection, self.items))[0] + basket = Basket.objects(__raw__={"items.collection": collection, "items.record_id": str(record_id)}).first() + + if basket: + return next(filter(lambda x: x['collection'] == collection and x['record_id'] == record_id, basket.items), None) def add_item(self, item): - existing_item = list(filter(lambda x: x['collection'] == item['collection'] and x['record_id'] == (item['record_id']), self.items)) + existing_item = Basket._get_collection().find_one({"items.collection": item['collection'], "items.record_id": item['record_id']}) if not existing_item: ulid = ULID() diff --git a/dlx_rest/tests/test_api.py b/dlx_rest/tests/test_api.py index e3de79c9..c5e18723 100644 --- a/dlx_rest/tests/test_api.py +++ b/dlx_rest/tests/test_api.py @@ -1,5 +1,4 @@ import io, os -from time import sleep os.environ['DLX_REST_TESTING'] = 'True' import pytest, json, re