-
Notifications
You must be signed in to change notification settings - Fork 707
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
base: master
Are you sure you want to change the base?
Solution #728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GJ
There was a problem hiding this 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:
-
Functionality Issues:
- The
TicketSerializer
'svalidate
method assumes thatmovie_session
is a fully populated instance with acinema_hall
attribute. Please ensure thatmovie_session
is fully populated or adjust the logic to handle cases where it might not be. - There is a typo in the
OrderSerializer
'screate
method, wheretickets_date
should betickets_data
. This needs to be corrected to ensure the functionality works as expected.
- The
-
Optimization and Security:
- In the
MovieSessionViewSet
, usingselect_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 therequest.user
is correctly set, especially if authentication is involved.
- In the
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.
cinema/serializers.py
Outdated
) | ||
|
||
|
||
class TicketSerializer(serializers.ModelSerializer): | ||
movie_session = MovieSessionSerializer() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
cinema/serializers.py
Outdated
|
||
def create(self, validated_data): | ||
with transaction.atomic(): | ||
tickets_date = validated_data.pop("tickets") |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
'svalidate
method correctly handles cases wheremovie_session
might not be fully populated. Also, make sure the typo in theOrderSerializer
'screate
method is corrected fromtickets_date
totickets_data
. -
Optimization: In the
MovieSessionViewSet
, specify fields when usingselect_related()
to avoid unnecessary database joins. -
Security: Filtering by
user=self.request.user
in theOrderViewSet
should be secure, especially if authentication is involved. -
Settings: Remember to keep your
SECRET_KEY
secret, setDEBUG
toFalse
in production, and configureALLOWED_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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
if date: | ||
date = parse_date(date) | ||
if date: |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?????
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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
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})" | ||
} | ||
) |
There was a problem hiding this comment.
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
No description provided.