Add: creators api app
This commit is contained in:
parent
72c0a012c9
commit
217ecaa253
7 changed files with 160 additions and 0 deletions
39
backend/api/creators/views.py
Normal file
39
backend/api/creators/views.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
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)
|
Loading…
Add table
Add a link
Reference in a new issue