Solution#1147
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Changes are needed before approval. First, the Movie endpoint is registered as 'Movies' (capitalized) in urls.py, views.py, and models.py, but the task requires lowercase 'movies' to match the api/cinema/<entity>/ pattern — this must be updated everywhere the router registers the viewset. Second, both GenreDetail and ActorDetail views are missing the patch() method required for partial updates via PATCH api/cinema/<entity>/<pk>/; you’ll need to add patch(self, request, pk) with appropriate logic using serializer.is_valid(raise_exception=True) and serializer.save(). Additionally, there’s an unused api_view import in serializers.py that should be removed, and a flake8 linting error (E202) on line 34 of views.py due to extraneous whitespace before a closing parenthesis — fix the spacing to comply with PEP 8. These are critical functional and specification mismatches, not just style issues.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| return self.name | ||
|
|
There was a problem hiding this comment.
The router registers 'Movies' with capital M. Per the task requirements, the endpoint should be 'movies' (lowercase). The task specifies 'api/cinema//' pattern with entities like 'actors', 'genres', 'cinema_halls', 'movies'.
| router = DefaultRouter() | ||
| router.register("cinema-halls", CinemaHallViewSet) |
There was a problem hiding this comment.
The router registers 'Movies' (capitalized) instead of 'movies'. Per the task requirements, the endpoint should use lowercase: 'api/cinema///' where includes 'movies', 'actors', 'genres', 'cinema_halls'.
|
|
||
| from cinema.models import Movie | ||
| from cinema.serializers import MovieSerializer | ||
|
|
There was a problem hiding this comment.
The router registers 'Movies' with capital M. Per the task requirements, the endpoint should use lowercase 'movies' to match the pattern specified: 'api/cinema//' where is 'movies'.
|
|
||
| class GenreDetail(APIView): | ||
| def get(self, request: Request, pk: int ) -> Response: | ||
| genre = get_object_or_404(Genre, pk=pk) | ||
| serializer = GenreSerializer(genre) | ||
| return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
|
||
| if request.method == "POST": | ||
| serializer = MovieSerializer(data=request.data) | ||
| if serializer.is_valid(): | ||
| serializer.save() | ||
| return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
| def put(self, request: Request, pk: int) -> Response: | ||
| genre = get_object_or_404(Genre, pk=pk) | ||
| serializer = GenreSerializer(genre, data=request.data) | ||
| 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 = get_object_or_404(Genre, pk=pk) | ||
| genre.delete() | ||
| return Response(status=status.HTTP_204_NO_CONTENT) |
There was a problem hiding this comment.
GenreDetail is missing the PATCH method. The task explicitly requires PATCH endpoint: 'PATCH api/cinema///' - should partially update the entity with given id based on passed data.
|
|
||
| return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
| class ActorDetail(GenericAPIView): | ||
| queryset = Actor.objects.all() | ||
| serializer_class = ActorSerializer | ||
|
|
||
| if request.method == "DELETE": | ||
| movie.delete() | ||
| def get(self, request: Request, pk: int) -> Response: | ||
| actor = get_object_or_404(Actor, pk=pk) | ||
| serializer = self.get_serializer(actor) | ||
| return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
|
||
| def put(self, request: Request, pk: int) -> Response: | ||
| actor = get_object_or_404(Actor, pk=pk) | ||
| serializer = self.get_serializer(actor, data=request.data) | ||
| 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: | ||
| actor = get_object_or_404(Actor, pk=pk) | ||
| actor.delete() | ||
| return Response(status=status.HTTP_204_NO_CONTENT) |
There was a problem hiding this comment.
ActorDetail is missing the PATCH method. The task explicitly requires PATCH endpoint: 'PATCH api/cinema///' - should partially update the entity with given id based on passed data.
| instance.first_name | ||
| ) |
There was a problem hiding this comment.
The router registers 'Movies' with capital M. Per task requirements, endpoints should follow 'api/cinema//' pattern with lowercase entity names like 'movies', not 'Movies'.
| return Genre.objects.create(**validated_data) | ||
|
|
||
| def update(self, instance, validated_data): | ||
| instance.name = validated_data.get("name", instance.name) | ||
| instance.save() | ||
| return instance | ||
|
|
||
|
|
||
| class CinemaHallSerializer(serializers.ModelSerializer): | ||
| id = serializers.IntegerField(read_only=True) | ||
| name = serializers.CharField(max_length=255) | ||
| rows = serializers.IntegerField() | ||
| seats_in_row = serializers.IntegerField() | ||
|
|
||
| def create(self, validated_data): | ||
| return CinemaHall.objects.create(**validated_data) | ||
|
|
||
| def update(self, instance, validated_data): |
There was a problem hiding this comment.
GenreDetail is missing the PATCH method for partial updates. The task specifies: 'PATCH api/cinema///' - should partially update the entity with given id based on passed data.
| queryset=Actor.objects.all() | ||
| ) | ||
| genres = serializers.PrimaryKeyRelatedField( | ||
| many=True, | ||
| queryset=Genre.objects.all() | ||
| ) | ||
|
|
||
| def create(self, validated_data): | ||
| return Movie.objects.create(**validated_data) | ||
| actors = validated_data.pop("actors") | ||
| genres = validated_data.pop("genres") | ||
| movie = Movie.objects.create(**validated_data) | ||
| movie.actors.set(actors) | ||
| movie.genres.set(genres) | ||
| return movie | ||
|
|
||
| def update(self, instance, validated_data): | ||
| actors = validated_data.pop("actors", None) | ||
| genres = validated_data.pop("genres", None) | ||
| instance.title = validated_data.get("title", instance.title) | ||
| instance.description = validated_data.get( | ||
| "description", instance.description |
There was a problem hiding this comment.
ActorDetail is missing the PATCH method for partial updates. The task specifies: 'PATCH api/cinema///' - should partially update the entity with given id based on passed data.
| from rest_framework import serializers | ||
|
|
||
| from cinema.models import Movie | ||
| from cinema.models import Actor, Genre, CinemaHall, Movie |
There was a problem hiding this comment.
Unused import. The 'api_view' decorator is imported but never used in this file.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The ActorDetail.patch() method in cinema/views.py is incomplete and will cause PATCH requests to fail — it creates a partial serializer but does not call serializer.is_valid(raise_exception=True), serializer.save(), or return a Response. This violates the requirement to support partial updates for actors and blocks functionality required by [CHECKLIST ITEM #2]. Additionally, there are flake8 linting issues: an unused variable on line 92 of views.py, and multiple E501 line-too-long violations across serializers.py, views.py, and settings.py. Please fix the critical patch() implementation first, then address the style issues to ensure clean, functional code.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
| def patch(self, request: Request, pk: int) -> Response: | ||
| actor = get_object_or_404(Actor, pk=pk) | ||
| serializer = self.get_serializer(actor, data=request.data, partial=True) |
There was a problem hiding this comment.
The patch() method is incomplete - it validates and creates a partial serializer but never calls is_valid(raise_exception=True), save(), or returns a Response. This will cause PATCH requests to fail.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution as an educational override to support your learning journey — great progress overall! You've correctly implemented all required models with proper fields, related_name='movies' for ManyToMany relationships [CHECKLIST ITEM #1], used the right view classes (APIView, GenericAPIView, GenericViewSet, ModelViewSet with routers), and applied proper error handling via serializer.is_valid(raise_exception=True) [CHECKLIST ITEM #2]. The import grouping in views.py also follows the recommended pattern with parentheses and one import per line [CHECKLIST ITEM #3]. There is a syntax error in cinema/serializers.py at line 54 (validated_data( should be validated_data.get(), which would cause a runtime NameError during CinemaHall updates — please fix that to ensure stability. Additionally, consider cleaning up the long lines in cinema_service/settings.py (lines 23, 95, 98, 101) to satisfy flake8’s 79-character limit. Keep up the excellent work — your architecture and Django REST Framework understanding are strong!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
vsmutok
left a comment
There was a problem hiding this comment.
Tests failed.
Please make sure your code passes all tests before submitting it for review.
No description provided.