Gallery-Archivist/backend/api/creators/views.py

40 lines
1.1 KiB
Python
Raw Normal View History

2025-02-12 13:23:35 +01:00
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.exceptions import NotFound
from rest_framework.permissions import IsAuthenticated
from apps.archive.models import CreatorModel
from .serializers import (
CreatorListSerializer,
CreatorDetailsSerializer,
)
class CreatorListView(APIView):
permission_classes = [IsAuthenticated]
def get(self, request):
user = request.user.userprofile
if user.show_mature:
creators = CreatorModel.objects.all()
else:
creators = CreatorModel.objects.filter(mature=False)
serializer = CreatorListSerializer(creators, many=True)
return Response(serializer.data)
class CreatorDetailsView(APIView):
permission_classes = [IsAuthenticated]
def get(self, request, creator_id):
try:
creator = CreatorModel.objects.get(creator_id=creator_id)
except CreatorModel.DoesNotExist:
raise NotFound(detail="Creator not found.")
serializer = CreatorDetailsSerializer(creator)
return Response(serializer.data)