Skip to content

Commit

Permalink
exclude if-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Katkalov committed Oct 18, 2023
1 parent 889013f commit 6bed61a
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ def get(self, request: Request) -> Response:

def post(self, request: Request) -> Response:
serialized_data = GenreSerializer(data=request.data)
if serialized_data.is_valid(raise_exception=True):
serialized_data.save()
return Response(
serialized_data.data, status=status.HTTP_201_CREATED
)
return Response(
serialized_data.errors, status=status.HTTP_400_BAD_REQUEST
)
serialized_data.is_valid(raise_exception=True)
serialized_data.save()
return Response(serialized_data.data, status=status.HTTP_201_CREATED)



class GenreDetail(APIView):
Expand All @@ -53,16 +49,16 @@ def get(self, request: Request, pk: int) -> Response:
def put(self, request: Request, pk: int) -> Response:
genre_object = self.get_object(pk=pk)
serializer = GenreSerializer(genre_object, data=request.data)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

def patch(self, request: Request, pk: int) -> Response:
genre_object = self.get_object(pk=pk)
serializer = GenreSerializer(genre_object, data=request.data)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

def delete(self, request: Request, pk: int) -> Response:
genre_object = self.get_object(pk=pk)
Expand Down

0 comments on commit 6bed61a

Please sign in to comment.