From 52f5bf33bbdfcee6589ee4e31ad7a5c8feaec8ea Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Fri, 4 Jan 2019 14:18:56 -0600 Subject: [PATCH] Selling command now fully replimented. --- api/commands.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/commands.py b/api/commands.py index 1ce5a58..c349530 100644 --- a/api/commands.py +++ b/api/commands.py @@ -227,12 +227,12 @@ def add_item(item_name, quantity, diamond_price, shop_name=None, discord_uuid=No return item_listing.json -# TODO Re-implement selling shop search @command("GET") -def selling(item_name): +def selling(item_name, sort="normalized_price"): ''' :request: GET :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 :help: List shops selling an item. Sorted by most recently added ''' @@ -242,11 +242,13 @@ def selling(item_name): raise EmptryString 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: raise ItemNotFound + shops = [i for n, i in enumerate(shops) if i not in shops[n + 1:]] + for shop_id in shops: shop = Shop.objects.get(pk=shop_id['shop_id']).json