You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.8 KiB
Python
89 lines
2.8 KiB
Python
import json
|
|
from django.http import JsonResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from app.api import api
|
|
from app.utils import decimal_to_float
|
|
|
|
@csrf_exempt
|
|
async def get_shop(request):
|
|
try:
|
|
products = None
|
|
if request.method == 'GET':
|
|
products = api.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 login(request):
|
|
try:
|
|
token = None
|
|
if request.method == 'POST':
|
|
body: dict = json.loads(request.body)
|
|
token = api.login(body["email"], body["password"])
|
|
return JsonResponse({"OK": token}, status=200)
|
|
except Exception as error:
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
@csrf_exempt
|
|
async def logout(request):
|
|
try:
|
|
token = None
|
|
if request.method == 'POST':
|
|
token = request.headers.get("Token")
|
|
api.logout(token)
|
|
return JsonResponse({"OK": token}, status=200)
|
|
except Exception as error:
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
@csrf_exempt
|
|
async def register(request):
|
|
try:
|
|
token = None
|
|
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)
|
|
except Exception as error:
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
@csrf_exempt
|
|
async def unregister(request):
|
|
try:
|
|
token = None
|
|
if request.method == 'POST':
|
|
token = request.headers.get("Token")
|
|
api.unregister(token)
|
|
return JsonResponse({"OK": token}, status=200)
|
|
except Exception as error:
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
@csrf_exempt
|
|
async def get_basket(request):
|
|
try:
|
|
basket = None
|
|
if request.method == 'POST':
|
|
token = request.headers.get("Token")
|
|
basket = api.get_basket(token)
|
|
return JsonResponse({"OK": basket}, status=200)
|
|
except Exception as error:
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
@csrf_exempt
|
|
async def get_history(request):
|
|
try:
|
|
histories = None
|
|
if request.method == 'POST':
|
|
token = request.headers.get("Token")
|
|
histories = api.get_histories(token)
|
|
return JsonResponse({"OK": histories}, status=200)
|
|
except Exception as error:
|
|
return JsonResponse({"error": format(error)}, status=500)
|
|
|
|
|
|
|