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

implement py-tickets-and-orders #863

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

Conversation

ValeriiaKyr
Copy link

No description provided.

db/models.py Outdated
created_at = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE

Choose a reason for hiding this comment

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

related name missing

db/models.py Outdated


class Ticket(models.Model):
movie_session = models.ForeignKey(MovieSession, on_delete=models.CASCADE)

Choose a reason for hiding this comment

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

related names missing

db/models.py Outdated
self.full_clean()
return super().save(*args, **kwargs)

class Meta:

Choose a reason for hiding this comment

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

as a convention in django Meta class is defined right after fields definition

movie_session_id=movie_session_id
).values("row", "seat")

return list(row_seats)

Choose a reason for hiding this comment

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

no need to store row_seats in a variable - just return whole expression in list()

date: str | None = None
) -> Order:

user = get_user_model().objects.get(username=username)

Choose a reason for hiding this comment

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

shouldn't this be as well under atomic decorator?

Choose a reason for hiding this comment

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

Lol this actually is a read operation that wouldn't need a rollback in case if something happens :)
But it is actually better to wrap the entire function in transaction

services/user.py Outdated
def create_user(
username: str,
password: Any,
email: str = None,

Choose a reason for hiding this comment

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

add annotation that these params are optional

services/user.py Outdated


def get_user(user_id: int) -> User:
return User.objects.get(id=user_id)

Choose a reason for hiding this comment

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

use get_user_model() here. Also use pk instead of id

services/user.py Outdated
def update_user(
user_id: int,
username: str | None = None,
password: Any | None = None,

Choose a reason for hiding this comment

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

shouldn't password be a string?

services/user.py Outdated

def create_user(
username: str,
password: Any,

Choose a reason for hiding this comment

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

Why Any?

services/user.py Outdated
first_name: str | None = None,
last_name: str | None = None
) -> None:
user = get_user_model().objects.get(pk=user_id)

Choose a reason for hiding this comment

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

you can reuse your get_user function here

db/models.py Outdated
from django.db import models
from django.db.models import UniqueConstraint

import settings
Copy link

Choose a reason for hiding this comment

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

it's better to use
from django.conf import settings
because you may want to have settings folder or your project has multiple settings files

db/models.py Outdated
Comment on lines 125 to 127
def save(self, *args, **kwargs) -> Any:
self.full_clean()
return super().save(*args, **kwargs)
Copy link

Choose a reason for hiding this comment

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

Are you sure it returns it? It returns None actually(you can hover your mouse on super.save and will see which type it should return

@@ -6,6 +7,7 @@
def get_movies(
genres_ids: list[int] = None,
actors_ids: list[int] = None,
title: str = None,
Copy link

Choose a reason for hiding this comment

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

str or None annotation. Fix everywhere

Choose a reason for hiding this comment

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

This haven't been added - you need to add annotation that this parameter can also be None

@@ -42,3 +44,9 @@ def update_movie_session(

def delete_movie_session_by_id(session_id: int) -> None:
MovieSession.objects.get(id=session_id).delete()
Copy link

Choose a reason for hiding this comment

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

follow dry and use get_movie_sessions

settings.py Outdated
Comment on lines 27 to 30
"db",
"django.contrib.auth",
"django.contrib.contenttypes",
]
Copy link

Choose a reason for hiding this comment

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

actually at the top should be default django apps, then yours

db/models.py Outdated
movie_session = models.ForeignKey(
MovieSession,
on_delete=models.CASCADE,
related_name="sessions_tickets"

Choose a reason for hiding this comment

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

just tickets would be enough here. Use case:
movie_session.tickets
OR
order.tickets
gives you access to Ticket table on corresponding model

@@ -6,6 +7,7 @@
def get_movies(
genres_ids: list[int] = None,
actors_ids: list[int] = None,
title: str = None,

Choose a reason for hiding this comment

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

This haven't been added - you need to add annotation that this parameter can also be None

# with transaction.atomic():
order = Order.objects.create(user=user)
if date:
order.created_at = parse_datetime(date)

Choose a reason for hiding this comment

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

you can pass date as is - no need for conversion here. Don't forget to clean up imports as well

Copy link

@Oleksl888 Oleksl888 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! 👏

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