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

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

Solution #747

wants to merge 3 commits into from

Conversation

zakotii
Copy link

@zakotii zakotii commented Jan 8, 2025

No description provided.

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 mostly on the right track, there are a few critical issues that need to be addressed before we can approve it:

  1. Redundancy in REST Framework Configuration: The DEFAULT_FILTER_BACKENDS is set twice in the settings file. This redundancy could lead to confusion and inconsistency. Please remove one of these entries to streamline the configuration.

  2. Typo in Model Reference: There's a typo in the reference to movie_session.cinema_hалл.seats_in_row. It should be movie_session.cinema_hall.seats_in_row. This typo could cause runtime errors, so it's important to correct it.

  3. Validation in TicketSerializer: The validate method should safely access movie_session using data.get('movie_session') to prevent potential KeyError exceptions. This will make your code more robust and user-friendly.

  4. Error Handling in filter_by_actor_ids: While catching a ValueError is a good practice, consider logging the error or providing feedback to the user. This will enhance debugging and improve the user experience.

Once these issues are addressed, your code will be in great shape! Keep up the good work, and feel free 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.

Comment on lines 33 to 44
def filter_by_actor_ids(self, queryset, name, value):
try:
# Преобразуем значения в список ID
actor_ids = [
int(id.strip())
for id in value.split(",")
if id.strip().isdigit()
]
return queryset.filter(actors__id__in=actor_ids)
except ValueError:
# Если передан некорректный ID
return queryset.none()

Choose a reason for hiding this comment

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

The filter_by_actor_ids method currently catches a ValueError if the IDs are not valid integers. This is a good practice, but consider logging the error or providing feedback to the user to improve debugging and user experience.

Comment on lines 45 to 55
movie_session = data["movie_session"]
row = data["row"]
seat = data["seat"]
if Ticket.objects.filter(
movie_session=movie_session, row=row, seat=seat
).exists():
raise serializers.ValidationError("Это место уже занято.")
if not (1 <= row <= movie_session.cinema_hall.rows):
raise serializers.ValidationError("Недопустимый номер ряда.")
if not (1 <= seat <= movie_session.cinema_hалл.seats_in_row):
raise serializers.ValidationError("Недопустимый номер места.")

Choose a reason for hiding this comment

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

In the validate method of TicketSerializer, ensure that movie_session is included in the data dictionary. If movie_session is not provided, this will raise a KeyError. Consider using data.get('movie_session') to safely access the value.

Comment on lines 54 to 55
if not (1 <= seat <= movie_session.cinema_hалл.seats_in_row):
raise serializers.ValidationError("Недопустимый номер места.")

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 movie_session.cinema_hалл.seats_in_row. It should be movie_session.cinema_hall.seats_in_row to correctly reference the CinemaHall model.

Comment on lines 142 to 150
REST_FRAMEWORK = {
"DEFAULT_FILTER_BACKENDS": (
"django_filters.rest_framework.DjangoFilterBackend",
),
}

REST_FRAMEWORK["DEFAULT_FILTER_BACKENDS"] = [
"django_filters.rest_framework.DjangoFilterBackend"
]

Choose a reason for hiding this comment

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

There is a redundancy in the REST framework configuration. The DEFAULT_FILTER_BACKENDS is set twice, once as a tuple and once as a list. You should remove one of these to avoid confusion and ensure consistency in the settings.

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.

Your Pull Request has been reviewed and is approved! 🎉

Review Summary:

Great job on addressing the previous issues and improving your code! Here are some key points from the review:

  • Redundancy in REST Framework Configuration: The DEFAULT_FILTER_BACKENDS was set twice in the settings file. Make sure to remove one of these entries to streamline the configuration.

  • Unused Methods in MovieSerializer: The get_genres and get_actors methods are not used in the serializer fields. Consider removing these methods to clean up the code.

  • Validation in TicketSerializer: You've improved the validate method by using data.get('movie_session') to safely access movie_session, preventing potential KeyError exceptions.

  • Error Handling in filter_by_actor_ids: Consider providing feedback to the user or handling errors more gracefully when an invalid actor ID is encountered. This will enhance the user experience and robustness of your application.

Your code is well-structured, and the critical issues have been addressed. Keep up the good work and continue to refine your skills. Remember to review the comments to further improve your code. This decision is made to help you move forward with your learning journey. 🚀

If there are any critical issues, make sure to address them in the future to avoid similar problems. Keep learning and improving! 😊

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

Comment on lines +46 to +50
except ValueError as e:
# Логируем ошибку для отладки
logger.warning(f"Invalid actor ID input: '{value}'. Error: {e}")
# Возвращаем пустой queryset, если данные некорректны
return queryset.none()

Choose a reason for hiding this comment

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

Consider providing feedback to the user or handling the error more gracefully when an invalid actor ID is encountered. This will improve the user experience and make the application more robust.

fields = ("id", "row", "seat", "movie_session")

def validate(self, data):
movie_session = data.get("movie_session")

Choose a reason for hiding this comment

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

Consider using data.get('movie_session') to safely access movie_session and prevent potential KeyError exceptions.

Comment on lines +116 to +123
def get_genres(self, obj):
return [genre.name for genre in obj.genres.all()]

def get_actors(self, obj):
return [
f"{actor.first_name} {actor.last_name}"
for actor in obj.actors.all()
]

Choose a reason for hiding this comment

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

The get_genres and get_actors methods are not used in the serializer fields. Consider removing these methods to clean up the code.

Comment on lines +142 to +146
REST_FRAMEWORK = {
"DEFAULT_FILTER_BACKENDS": (
"django_filters.rest_framework.DjangoFilterBackend",
),
}

Choose a reason for hiding this comment

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

The DEFAULT_FILTER_BACKENDS is set twice in the settings file. Please remove one of these entries to streamline the configuration.

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.

2 participants