Selling command now fully replimented.

doc_update
Joey Hines 2019-01-04 14:18:56 -06:00
parent 00fe2d72ab
commit 52f5bf33bb
1 changed files with 5 additions and 3 deletions

View File

@ -227,12 +227,12 @@ def add_item(item_name, quantity, diamond_price, shop_name=None, discord_uuid=No
return item_listing.json return item_listing.json
# TODO Re-implement selling shop search
@command("GET") @command("GET")
def selling(item_name): def selling(item_name, sort="normalized_price"):
''' '''
:request: GET :request: GET
:param item_name: Item name to search for :param item_name: Item name to search for
:param sort: Field to sort shop results by
:return: List of top matches shop, sorted by when they were added :return: List of top matches shop, sorted by when they were added
:help: List shops selling an item. Sorted by most recently added :help: List shops selling an item. Sorted by most recently added
''' '''
@ -242,11 +242,13 @@ def selling(item_name):
raise EmptryString raise EmptryString
shops = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \ shops = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \
.filter(item_name__icontains=item_name).order_by('normalized_price').values('shop_id').distinct() .filter(item_name__icontains=item_name).order_by(sort).values('shop_id').all()
if len(shops) == 0: if len(shops) == 0:
raise ItemNotFound raise ItemNotFound
shops = [i for n, i in enumerate(shops) if i not in shops[n + 1:]]
for shop_id in shops: for shop_id in shops:
shop = Shop.objects.get(pk=shop_id['shop_id']).json shop = Shop.objects.get(pk=shop_id['shop_id']).json