Skip to content

Commit

Permalink
fazendo a modelagem e o schema da tabela liked
Browse files Browse the repository at this point in the history
  • Loading branch information
leticosta4 committed Feb 3, 2024
1 parent 1d81f86 commit d4f04f3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/models/schemas/liked_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from app.config.app_config import *
from app.config.db_config import *
from app.models.tables.liked import Liked
from app.models.schemas.user_schema import UserSchema
from app.models.schemas.movie_schema import MovieSchema

class LikedSchema(ma.SQLAlchemyAutoSchema):
user = ma.Nested(UserSchema)
movie = ma.Nested(MovieSchema)
class Meta:
model = Liked
load_instance = True
2 changes: 1 addition & 1 deletion app/models/tables/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app.models.tables.movie import Movie
from datetime import datetime
from sqlalchemy.orm import Mapped, mapped_column, relationship, backref
from sqlalchemy import String, Integer, DateTime, Text
from sqlalchemy import String, DateTime
from uuid import uuid4


Expand Down
14 changes: 14 additions & 0 deletions app/models/tables/liked.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from app.config.app_config import *
from app.config.db_config import *
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import String, ForeignKey
from uuid import uuid4

class Liked(Base):
id: Mapped[str] = mapped_column(String, primary_key=True, default=lambda: str(uuid4()))
user_id: Mapped[str] = mapped_column(String, ForeignKey("user.id"), unique=False, nullable=True)
movie_id: Mapped[str] = mapped_column(String, ForeignKey("movie.id"), unique=False, nullable=True)

def __init__(self, user_id, movie_id):
self.user_id = user_id
self.movie_id = movie_id
4 changes: 3 additions & 1 deletion app/models/tables/movie.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from app.config.app_config import *
from app.config.db_config import *
from sqlalchemy.orm import Mapped, mapped_column
from app.models.tables.liked import Liked
from sqlalchemy.orm import Mapped, mapped_column, relationship, backref
from sqlalchemy import String, Text, Integer, Double, ForeignKey
from uuid import uuid4

Expand All @@ -19,6 +20,7 @@ class Movie(Base):
launch_date: Mapped[str] = mapped_column(String(45), unique=False, nullable=False)
running_time: Mapped[int] = mapped_column(Integer, unique=True, nullable=False)
category_id: Mapped[str] = mapped_column(String, ForeignKey("category.id"), unique=False, nullable=False)
liked = relationship('Liked', backref='movie')


def __init__(self, title: str, original_title: str, romanised_original_title: str,
Expand Down
4 changes: 3 additions & 1 deletion app/models/tables/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from app.config.app_config import *
from app.config.db_config import *
from app.models.tables.liked import Liked
from datetime import datetime
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.orm import Mapped, mapped_column, relationship, backref
from sqlalchemy import String, Text
from uuid import uuid4

Expand All @@ -12,6 +13,7 @@ class User(Base):
username: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
email: Mapped[str] = mapped_column(String(320), unique=True, nullable=False)
password_hash: Mapped[str] = mapped_column(Text, unique=False, nullable=False)
#liked = relationship('Liked', backref='user')

def __init__(self, name:str, username:str, email:str, password_hash:str):
self.name = name
Expand Down

0 comments on commit d4f04f3

Please sign in to comment.