from rest_framework.views import APIView
from rest_framework.response import Response
from django.shortcuts import get_object_or_404
from rest_framework import status
from .models import Stock
from .serializers import StockSerializer
from django.http import Http404
# Create your views here.
class StockList(APIView):

    def get(self, request, format=None):
        stocks = Stock.objects.all()
        serializer = StockSerializer(stocks, many=True)
        return Response(serializer.data)

    def post(self, request, format=None):
        serializer = StockSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class StockDetails(APIView):

    def get_object(self, pk):
        try:
            return Stock.objects.get(pk=pk)
        except Stock.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        stocks = self.get_object(pk)
        stocks.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)


268f2fbf83e15a204527d156e4f5e1acf4f15f75
<mask token>


class StockDetails(APIView):

    def get_object(self, pk):
        try:
            return Stock.objects.get(pk=pk)
        except Stock.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks)
        return Response(serializer.data)
    <mask token>

    def delete(self, request, pk, format=None):
        stocks = self.get_object(pk)
        stocks.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

<mask token>


class StockDetails(APIView):

    def get_object(self, pk):
        try:
            return Stock.objects.get(pk=pk)
        except Stock.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        stocks = self.get_object(pk)
        stocks.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

<mask token>


class StockList(APIView):
    <mask token>
    <mask token>


class StockDetails(APIView):

    def get_object(self, pk):
        try:
            return Stock.objects.get(pk=pk)
        except Stock.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        stocks = self.get_object(pk)
        stocks.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

<mask token>


class StockList(APIView):

    def get(self, request, format=None):
        stocks = Stock.objects.all()
        serializer = StockSerializer(stocks, many=True)
        return Response(serializer.data)

    def post(self, request, format=None):
        serializer = StockSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class StockDetails(APIView):

    def get_object(self, pk):
        try:
            return Stock.objects.get(pk=pk)
        except Stock.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        stocks = self.get_object(pk)
        stocks.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

from rest_framework.views import APIView
from rest_framework.response import Response
from django.shortcuts import get_object_or_404
from rest_framework import status
from .models import Stock
from .serializers import StockSerializer
from django.http import Http404
# Create your views here.
class StockList(APIView):

    def get(self, request, format=None):
        stocks = Stock.objects.all()
        serializer = StockSerializer(stocks, many=True)
        return Response(serializer.data)

    def post(self, request, format=None):
        serializer = StockSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class StockDetails(APIView):

    def get_object(self, pk):
        try:
            return Stock.objects.get(pk=pk)
        except Stock.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        stocks = self.get_object(pk)
        serializer = StockSerializer(stocks, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        stocks = self.get_object(pk)
        stocks.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

