Skip to content

Commit

Permalink
adding items to basket optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jbukhari authored and jbukhari committed Apr 4, 2024
1 parent aaca11f commit 2dfc6c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 5 additions & 2 deletions dlx_rest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion dlx_rest/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io, os
from time import sleep
os.environ['DLX_REST_TESTING'] = 'True'

import pytest, json, re
Expand Down

0 comments on commit 2dfc6c8

Please sign in to comment.