Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslav-mazurkevych committed Oct 16, 2023
1 parent 25e13c3 commit f9c50eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
2 changes: 0 additions & 2 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def update(self, instance, validated_data):
"description", instance.description
)
instance.duration = validated_data.get("duration", instance.duration)
# instance.actors.set(validated_data.get("actors", instance.actors))
# instance.genres.set(validated_data.get("genres", instance.genres))

instance.save()

Expand Down
12 changes: 3 additions & 9 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ def get(self, request: Request) -> Response:
def post(self, request: Request) -> Response:
serializer = GenreSerializer(data=request.data)

if serializer.is_valid():
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


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

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

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

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

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

0 comments on commit f9c50eb

Please sign in to comment.