Bug fix for book queries with no matches

This commit is contained in:
Reckless_Satoshi 2022-01-03 06:39:59 -08:00
parent e9bcd23347
commit 87fdaffa24
No known key found for this signature in database
GPG Key ID: 9C4585B561315571

View File

@ -191,6 +191,9 @@ class BookView(APIView):
currency = request.GET.get('currency_code')
type = request.GET.get('order_type')
queryset = Order.objects.filter(currency=currency, type=type)
if len(queryset)== 0:
return Response({'not_found':'No orders found, be the first to make one.'}, status=status.HTTP_404_NOT_FOUND)
book_data = {}
for i, order in enumerate(queryset):
data = OrderSerializer(order).data
@ -201,7 +204,8 @@ class BookView(APIView):
# TODO avoid sending status and takers for book views
#data.pop('status','taker')
book_data[i] = data
return Response(book_data,status.HTTP_200_OK)
return Response(book_data, status=status.HTTP_200_OK)