robosats/api/views.py

40 lines
1.3 KiB
Python
Raw Normal View History

2022-01-01 23:06:47 +00:00
from rest_framework import status
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.
class MakeOrder(APIView):
serializer_class = MakeOrderSerializer
2022-01-01 23:06:47 +00:00
def post(self,request):
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)