from django.shortcuts import render
from rest_framework.generics import ListCreateAPIView
from rest_framework.permissions import IsAuthenticated

from utils.models import JsonToType
from utils.serializers import JsonToTypeSerializer


# Create your views here.
class JsonToTypeListCreate(ListCreateAPIView):
    permission_classes = [IsAuthenticated]
    serializer_class = JsonToTypeSerializer

    def get_queryset(self):
        return JsonToType.objects.filter(user=self.request.user, is_active=True).order_by('-updated_at')

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)
