|
|
|
|
@ -2,8 +2,8 @@ import json
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
|
|
|
|
|
from backend.api import api
|
|
|
|
|
from backend.utils import decimal_to_float
|
|
|
|
|
from api import api
|
|
|
|
|
from utils import decimal_to_float, format_token
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
async def shop(request):
|
|
|
|
|
@ -14,9 +14,9 @@ async def shop(request):
|
|
|
|
|
user_agent = request.headers.get('User-Agent')
|
|
|
|
|
products = decimal_to_float(products)
|
|
|
|
|
print("get_shop", user_agent)
|
|
|
|
|
return JsonResponse({"OK": products}, status=200)
|
|
|
|
|
return JsonResponse({"success": products}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"ERROR": format(error)}, status=500)
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
async def user(request):
|
|
|
|
|
@ -33,22 +33,22 @@ async def user(request):
|
|
|
|
|
token = api.login(body["login"]["email"],
|
|
|
|
|
body["login"]["password"])
|
|
|
|
|
elif body["unregister"]:
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.unregister(token)
|
|
|
|
|
elif body["logout"]:
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.logout(token)
|
|
|
|
|
elif body["add_money"]:
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.add_money(token, body["add_money"]["money"])
|
|
|
|
|
else:
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
|
|
|
|
|
user1 = api.get_user(token)
|
|
|
|
|
|
|
|
|
|
return JsonResponse({"OK": user1}, status=200)
|
|
|
|
|
return JsonResponse({"success": list(user1)}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"ERROR": format(error)}, status=500)
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
@ -56,22 +56,23 @@ async def basket(request):
|
|
|
|
|
try:
|
|
|
|
|
basket1 = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
|
|
|
|
|
if body["add_product"]:
|
|
|
|
|
api.add_product_to_basket(token, body["add_product"]["product_id"])
|
|
|
|
|
elif body["delete_product"]:
|
|
|
|
|
api.delete_product_from_basket(token, body["delete_product"]["product_id"])
|
|
|
|
|
elif body["clear"]:
|
|
|
|
|
api.clear_basket(token)
|
|
|
|
|
elif body["buy_products"]:
|
|
|
|
|
api.buy_products(token)
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
|
|
|
|
|
if request.body:
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
if body["add_product"]:
|
|
|
|
|
api.add_product_to_basket(token, body["add_product"]["product_id"])
|
|
|
|
|
elif body["delete_product"]:
|
|
|
|
|
api.delete_product_from_basket(token, body["delete_product"]["product_id"])
|
|
|
|
|
elif body["clear"]:
|
|
|
|
|
api.clear_basket(token)
|
|
|
|
|
elif body["buy_products"]:
|
|
|
|
|
api.buy_products(token)
|
|
|
|
|
|
|
|
|
|
products_id = api.get_products_id(token, "basket")
|
|
|
|
|
basket1 = api.get_products_by_id(products_id)
|
|
|
|
|
|
|
|
|
|
return JsonResponse({"OK": basket1}, status=200)
|
|
|
|
|
return JsonResponse({"success": basket1}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -80,9 +81,9 @@ async def history(request):
|
|
|
|
|
try:
|
|
|
|
|
histories = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
basket1 = api.get_histories_with_products(token)
|
|
|
|
|
return JsonResponse({"OK": histories}, status=200)
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
histories = api.get_histories_with_products(token)
|
|
|
|
|
return JsonResponse({"success": histories}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -93,7 +94,7 @@ async def login(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = api.login(body["email"], body["password"])
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -102,9 +103,9 @@ async def logout(request):
|
|
|
|
|
try:
|
|
|
|
|
token = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.logout(token)
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -115,7 +116,7 @@ async def register(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = api.registration(body["nickname"], body["password"], body["email"])
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -124,9 +125,9 @@ async def unregister(request):
|
|
|
|
|
try:
|
|
|
|
|
token = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.unregister(token)
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -136,9 +137,9 @@ async def add_product_to_basket(request):
|
|
|
|
|
token = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.add_product_to_basket(token, body["product_id"])
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -148,9 +149,9 @@ async def delete_product_from_basket(request):
|
|
|
|
|
token = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.delete_product_from_basket(token, body["product_id"])
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -160,9 +161,9 @@ async def buy_products(request):
|
|
|
|
|
token = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.buy_products(token)
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
@ -172,9 +173,9 @@ async def clear_basket(request):
|
|
|
|
|
token = None
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
body: dict = json.loads(request.body)
|
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
|
token = format_token(request.headers.get("Authorization"))
|
|
|
|
|
api.clear_basket(token)
|
|
|
|
|
return JsonResponse({"OK": token}, status=200)
|
|
|
|
|
return JsonResponse({"success": token}, status=200)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|
|
|
|
|