Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
markus2812 committed Nov 3, 2023
1 parent 2e02000 commit feb6f22
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class ActorList(
queryset = Actor.objects.all()
serializer_class = ActorSerializer

def get(self, request, *args, **kwargs):
def get(self, request, *args, **kwargs) -> Response:
return self.list(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs) -> Response:
return self.create(request, *args, **kwargs)


Expand All @@ -55,53 +55,53 @@ class ActorDetail(
queryset = Actor.objects.all()
serializer_class = ActorSerializer

def get(self, request, *args, **kwargs):
def get(self, request, *args, **kwargs) -> Response:
return self.retrieve(request, *args, **kwargs)

def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)

def patch(self, request, *args, **kwargs):
def patch(self, request, *args, **kwargs) -> Response:
actor = self.get_object()
serializer = ActorSerializer(actor, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

def delete(self, request, *args, **kwargs):
def delete(self, request, *args, **kwargs) -> Response:
return self.destroy(request, *args, **kwargs)


class GenreList(APIView):
def get(self, request):
def get(self, request) -> Response:
genre = Genre.objects.all()
serializer = GenreSerializer(genre, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

def post(self, request):
def post(self, request) -> Response:
serializer = GenreSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)


class GenreDetail(APIView):
def get_object(self, pk):
def get_object(self, pk) -> Genre:
return get_object_or_404(Genre, pk=pk)

def get(self, request, pk):
def get(self, request, pk) -> Response:
genre = self.get_object(pk)
serializer = GenreSerializer(genre)
return Response(serializer.data, status=status.HTTP_200_OK)

def put(self, request, pk):
def put(self, request, pk) -> Response:
genre = self.get_object(pk)
serializer = GenreSerializer(genre, data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

def patch(self, request, pk):
def patch(self, request, pk) -> Response:
genre = self.get_object(pk)
serializer = GenreSerializer(
genre,
Expand All @@ -112,7 +112,7 @@ def patch(self, request, pk):
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

def delete(self, request, pk):
def delete(self, request, pk) -> Response:
genre = self.get_object(pk)
genre.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

0 comments on commit feb6f22

Please sign in to comment.