2022-01-01 23:06:47 +00:00
|
|
|
from rest_framework import status
|
2022-01-01 22:34:23 +00:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
|
|
from .serializers import OrderSerializer, MakeOrderSerializer
|
|
|
|
from .models import Order
|
2022-01-01 22:13:27 +00:00
|
|
|
|
|
|
|
# Create your views here.
|
2022-01-01 22:34:23 +00:00
|
|
|
|
|
|
|
class MakeOrder(APIView):
|
|
|
|
serializer_class = MakeOrderSerializer
|
|
|
|
|
2022-01-01 23:06:47 +00:00
|
|
|
def post(self,request):
|
2022-01-01 22:34:23 +00:00
|
|
|
|
|
|
|
serializer = self.serializer_class(data=request.data)
|
|
|
|
print(serializer)
|
|
|
|
if serializer.is_valid():
|
|
|
|
otype = serializer.data.get('type')
|
|
|
|
currency = serializer.data.get('currency')
|
|
|
|
amount = serializer.data.get('amount')
|
|
|
|
premium = serializer.data.get('premium')
|
|
|
|
satoshis = serializer.data.get('satoshis')
|
|
|
|
|
|
|
|
#################
|
|
|
|
# TODO
|
|
|
|
# query if the user is already a maker or taker, return error
|
|
|
|
|
|
|
|
# Creates a new order in db
|
|
|
|
order = Order(
|
|
|
|
type=otype,
|
|
|
|
currency=currency,
|
|
|
|
amount=amount,
|
|
|
|
premium=premium,
|
|
|
|
satoshis=satoshis)
|
|
|
|
order.save()
|
|
|
|
|
|
|
|
if not serializer.is_valid():
|
|
|
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
return Response(OrderSerializer(order).data, status=status.HTTP_201_CREATED)
|