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 #728

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

Solution #728

wants to merge 4 commits into from

Conversation

Den-k0
Copy link

@Den-k0 Den-k0 commented Dec 13, 2024

No description provided.

Copy link

@Atikiho Atikiho left a comment

Choose a reason for hiding this comment

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

GJ

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 project! While your code meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Functionality Issues:

    • The TicketSerializer's validate method assumes that movie_session is a fully populated instance with a cinema_hall attribute. Please ensure that movie_session is fully populated or adjust the logic to handle cases where it might not be.
    • There is a typo in the OrderSerializer's create method, where tickets_date should be tickets_data. This needs to be corrected to ensure the functionality works as expected.
  2. Optimization and Security:

    • In the MovieSessionViewSet, using select_related() without specifying fields can lead to unnecessary database joins. Consider specifying the fields to optimize the query.
    • Ensure that filtering by user=self.request.user is secure and that the request.user is correctly set, especially if authentication is involved.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you need any 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 TicketSerializer(serializers.ModelSerializer):
movie_session = MovieSessionSerializer()

Choose a reason for hiding this comment

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

The movie_session field in TicketSerializer is using MovieSessionSerializer, which may not provide the full cinema_hall object required in the validate method. Consider using a primary key related field or ensuring the full object is available.

movie_session = attrs.get("movie_session")
row = attrs.get("row")
seat = attrs.get("seat")
cinema_hall = movie_session.cinema_hall

Choose a reason for hiding this comment

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

The cinema_hall attribute is accessed directly from movie_session. Ensure that movie_session is a fully populated instance, or adjust the logic to handle cases where it might not be.


def create(self, validated_data):
with transaction.atomic():
tickets_date = validated_data.pop("tickets")

Choose a reason for hiding this comment

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

There seems to be a typo: tickets_date should likely be tickets_data to match the context of handling ticket information.

cinema/views.py Outdated
if self.action in "list":
return (
queryset
.select_related()

Choose a reason for hiding this comment

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

Using select_related() without specifying fields can lead to unnecessary database joins. Consider specifying the fields to optimize the query.

pagination_class = OrderSetPagination

def get_queryset(self):
queryset = self.queryset.filter(user=self.request.user)

Choose a reason for hiding this comment

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

Ensure that filtering by user=self.request.user is secure and that the request.user is correctly set, especially if authentication is involved.

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 addressing the previous issues in your code! 🎉 Your serializers, URL configurations, and viewsets are mostly well-implemented. However, there are a few critical points to keep in mind:

  • Functionality: Ensure that the TicketSerializer's validate method correctly handles cases where movie_session might not be fully populated. Also, make sure the typo in the OrderSerializer's create method is corrected from tickets_date to tickets_data.

  • Optimization: In the MovieSessionViewSet, specify fields when using select_related() to avoid unnecessary database joins.

  • Security: Filtering by user=self.request.user in the OrderViewSet should be secure, especially if authentication is involved.

  • Settings: Remember to keep your SECRET_KEY secret, set DEBUG to False in production, and configure ALLOWED_HOSTS appropriately.

These improvements are crucial for the functionality, optimization, and security of your application. Keep up the good work, and continue learning from these experiences to enhance your coding skills! 🚀

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

{"movie_session": "Movie session is required to validate row and seat."}
)

cinema_hall = movie_session.cinema_hall

Choose a reason for hiding this comment

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

The validate method in TicketSerializer assumes that movie_session is a fully populated instance with a cinema_hall attribute. Ensure that movie_session is fully populated or adjust the logic to handle cases where it might not be.


def create(self, validated_data):
with transaction.atomic():
tickets_data = validated_data.pop("tickets")

Choose a reason for hiding this comment

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

There is a typo in the OrderSerializer's create method. The variable tickets_date should be tickets_data to match the context and ensure the functionality works as expected.

if self.action in "list":
return (
queryset
.select_related("movie", "cinema_hall")

Choose a reason for hiding this comment

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

In the MovieSessionViewSet, using select_related() without specifying fields can lead to unnecessary database joins. Consider specifying the fields to optimize the query.

pagination_class = OrderSetPagination

def get_queryset(self):
queryset = self.queryset.filter(user=self.request.user)

Choose a reason for hiding this comment

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

Ensure that filtering by user=self.request.user is secure and that the request.user is correctly set, especially if authentication is involved. This is crucial for maintaining data privacy and security.

cinema/views.py Outdated
@@ -11,7 +22,7 @@
MovieSessionListSerializer,
MovieDetailSerializer,
MovieSessionDetailSerializer,
MovieListSerializer,
MovieListSerializer, OrderSerializer, OrderListSerializer,
Copy link
Contributor

Choose a reason for hiding this comment

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

fix style

cinema/views.py Outdated
Comment on lines 102 to 104
if date:
date = parse_date(date)
if date:
Copy link
Contributor

Choose a reason for hiding this comment

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

too many checking

cinema/views.py Outdated
if movie:
queryset = queryset.filter(movie_id=movie)

if self.action in "list":
Copy link
Contributor

Choose a reason for hiding this comment

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

?????

Copy link
Contributor

Choose a reason for hiding this comment

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

you should use in with list, tuple or dict object

cinema/views.py Outdated
)
)
)
elif self.action in "retrieve":
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use in... use == here

@Den-k0 Den-k0 requested a review from Nattalli December 16, 2024 21:56
Comment on lines +107 to +120
for ticket_attr_value, ticket_attr_name, cinema_hall_attr_name in [
(row, "row", "rows"),
(seat, "seat", "seats_in_row"),
]:
count_attrs = getattr(cinema_hall, cinema_hall_attr_name)
if not (1 <= ticket_attr_value <= count_attrs):
raise serializers.ValidationError(
{
ticket_attr_name: f"{ticket_attr_name} "
f"number must be in available range: "
f"(1, {cinema_hall_attr_name}): "
f"(1, {count_attrs})"
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

hm probably would be better to create a validation method in the model with @staticmethod decorator. And use it here

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.

4 participants