Skip to content

Commit

Permalink
Update solution
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-lybid committed Oct 16, 2023
1 parent f92e65c commit a0b9786
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ venv/
.pytest_cache/
**__pycache__/
*.pyc
db.sqlite3
db.sqlite3
21 changes: 9 additions & 12 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def get(self, request):

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


class GenreDetail(APIView):
Expand All @@ -43,18 +42,16 @@ def get(self, request, pk):
def put(self, request, pk):
genre = self.get_object(pk)
serializer = GenreSerializer(genre, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

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

def delete(self, request, pk):
genre = self.get_object(pk)
Expand Down

0 comments on commit a0b9786

Please sign in to comment.