import json from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from api import get_products from utils import decimal_to_float @csrf_exempt async def get_shop(request): try: products = None if request.method == 'GET': products = get_products() user_agent = request.headers.get('User-Agent') products = decimal_to_float(products) print("get_shop", user_agent) return JsonResponse({"OK": products}, status=200) except Exception as error: return JsonResponse({"ERROR": format(error)}, status=500) @csrf_exempt async def get_user(request): try: if request.method == 'POST': body: dict = json.loads(request.body) # TODO: вызвать API метод и вернуть JSON print("get_user", body) return JsonResponse({"OK": "JSON cleared"}, status=200) except Exception as error: return JsonResponse({"error": format(error)}, status=500) @csrf_exempt async def get_basket(request): try: if request.method == 'POST': body: dict = json.loads(request.body) # TODO: вызвать API метод и вернуть JSON print("get_basket", body) return JsonResponse({"OK": "JSON cleared"}, status=200) except Exception as error: return JsonResponse({"error": format(error)}, status=500) @csrf_exempt async def get_history(request): try: if request.method == 'POST': body: dict = json.loads(request.body) # TODO: вызвать API метод и вернуть JSON print("get_history", body) return JsonResponse({"OK": "JSON cleared"}, status=200) except Exception as error: return JsonResponse({"error": format(error)}, status=500)