Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #718

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

YaroslavBordovoy
Copy link

No description provided.

Copy link

@skyfoxwork skyfoxwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on this pull request! 😊 While your code is well-structured and meets most of the requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Validation in OrderSerializer: The create method in OrderSerializer does not validate the tickets data before creating Ticket instances. This could lead to invalid data being saved to the database. Please use TicketSerializer to validate each ticket entry to ensure data integrity.

  2. Queryset Modification: In both MovieViewSet and MovieSessionViewSet, you are modifying self.queryset directly in the get_queryset method. This can lead to unexpected behavior if the method is called multiple times. Consider using a local variable to store the filtered queryset and return it at the end of the method.

These changes are crucial for maintaining the functionality and reliability of your application. Once these issues are resolved, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you have any questions or need further assistance. 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.



class OrderSerializer(serializers.ModelSerializer):
tickets = TicketSerializer(many=True, read_only=False, allow_empty=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tickets field in OrderSerializer is set to read_only=False, which means you expect to receive data for tickets when creating an order. However, the create method does not validate this data using the TicketSerializer. Consider using TicketSerializer to validate each ticket entry before creating Ticket instances in the create method.

Comment on lines +120 to +127
def create(self, validated_data):
with transaction.atomic():
tickets_data = validated_data.pop("tickets")
order = Order.objects.create(**validated_data)
for ticket_data in tickets_data:
Ticket.objects.create(order=order, **ticket_data)

return order

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the create method of OrderSerializer, you should validate tickets_data using TicketSerializer before creating Ticket instances. This ensures that only valid data is saved to the database. You can iterate over tickets_data, use TicketSerializer(data=ticket_data) for each item, call is_valid(), and then save() if valid.

cinema/views.py Outdated Show resolved Hide resolved
cinema/views.py Outdated Show resolved Hide resolved
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on your progress! 🎉 Your implementation is well-structured, and you've made significant improvements. Here are a few key points to focus on:

  1. Validation in OrderSerializer: It's crucial to validate the tickets data using TicketSerializer before creating Ticket instances. This ensures data integrity and prevents invalid data from being saved to the database. Please iterate over tickets_data and use TicketSerializer(data=ticket_data) for validation.

  2. Queryset Modification: You've successfully addressed the issue of modifying self.queryset directly in the get_queryset methods of both MovieViewSet and MovieSessionViewSet. Using a local variable to store the filtered queryset is a great approach.

Remember, addressing these issues will enhance the robustness and reliability of your code. Keep up the good work, and continue learning from these experiences. Your dedication to improving your skills is commendable! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +120 to +127
def create(self, validated_data):
with transaction.atomic():
tickets_data = validated_data.pop("tickets")
order = Order.objects.create(**validated_data)
for ticket_data in tickets_data:
Ticket.objects.create(order=order, **ticket_data)

return order

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create method in OrderSerializer does not validate the tickets data before creating Ticket instances. This could lead to invalid data being saved to the database. Please use TicketSerializer to validate each ticket entry to ensure data integrity. You can iterate over tickets_data and use TicketSerializer(data=ticket_data) to validate each ticket.

Comment on lines +45 to +62
queryset = self.queryset

genres = self.request.query_params.get("genres")
actors = self.request.query_params.get("actors")
title = self.request.query_params.get("title")

if genres:
genres = self._params_to_ints(genres)
queryset = queryset.filter(genres__id__in=genres)

if actors:
actors = self._params_to_ints(actors)
queryset = queryset.filter(actors__id__in=actors)

if title:
queryset = queryset.filter(title__icontains=title)

return queryset.distinct()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the get_queryset method of MovieViewSet, you are modifying self.queryset directly. This can lead to unexpected behavior if the method is called multiple times. Consider using a local variable to store the filtered queryset and return it at the end of the method.

Comment on lines +79 to +101
queryset = self.queryset

date = self.request.query_params.get("date")
movie = self.request.query_params.get("movie")

if date:
queryset = queryset.filter(show_time__date=date)

if movie:
movie_ids = [int(str_id) for str_id in movie.split(",")]
queryset = queryset.filter(movie__id__in=movie_ids)

if self.action == "list":
queryset = queryset.select_related(
"cinema_hall",
"movie",
).annotate(
tickets_available=F("cinema_hall__rows")
* F("cinema_hall__seats_in_row")
- Count("tickets")
)

return queryset.distinct()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the get_queryset method of MovieSessionViewSet, you are modifying self.queryset directly. This can lead to unexpected behavior if the method is called multiple times. Consider using a local variable to store the filtered queryset and return it at the end of the method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants