mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 12:20:38 +04:00
Complete genres and actors
This commit is contained in:
@@ -21,14 +21,18 @@ class AudiobooksCRUD(EntityCRUD[mdl.Audiobook]):
|
||||
async def change_genres(db: AsyncSession, audiobook: mdl.Audiobook, info: sch.AudiobookCreate):
|
||||
audiobook_genres = await AudiobookGenresCRUD.get_all(db)
|
||||
if (info.genres):
|
||||
genres_id = [genre.id for genre in info.genres]
|
||||
audiobook.genres = [
|
||||
genre for genre in audiobook_genres if genre.id in info.genres]
|
||||
genre for genre in audiobook_genres if genre.id in genres_id]
|
||||
|
||||
@staticmethod
|
||||
async def add(db: AsyncSession,
|
||||
info: sch.AudiobookCreate,
|
||||
owner_id: int):
|
||||
audiobook = mdl.Audiobook(**info.model_dump(),
|
||||
audiobook_data_db = \
|
||||
{k: v for k, v in info.model_dump().items()
|
||||
if not k in ["genres", "update_date"]}
|
||||
audiobook = mdl.Audiobook(**audiobook_data_db,
|
||||
update_date=strftime("%Y-%m-%d %H:%M:%S"),
|
||||
owner_id=owner_id)
|
||||
await AudiobooksCRUD.change_genres(db, audiobook, info)
|
||||
|
||||
@@ -21,14 +21,18 @@ class GamesCRUD(EntityCRUD[mdl.Game]):
|
||||
async def change_genres(db: AsyncSession, game: mdl.Game, info: sch.GameCreate):
|
||||
game_genres = await GameGenresCRUD.get_all(db)
|
||||
if (info.genres):
|
||||
genres_id = [genre.id for genre in info.genres]
|
||||
game.genres = [
|
||||
genre for genre in game_genres if genre.id in info.genres]
|
||||
genre for genre in game_genres if genre.id in genres_id]
|
||||
|
||||
@staticmethod
|
||||
async def add(db: AsyncSession,
|
||||
info: sch.GameCreate,
|
||||
owner_id: int):
|
||||
game = mdl.Game(**info.model_dump(),
|
||||
game_data_db = \
|
||||
{k: v for k, v in info.model_dump().items()
|
||||
if not k in ["genres", "update_date"]}
|
||||
game = mdl.Game(**game_data_db,
|
||||
update_date=strftime("%Y-%m-%d %H:%M:%S"),
|
||||
owner_id=owner_id)
|
||||
await GamesCRUD.change_genres(db, game, info)
|
||||
|
||||
@@ -22,21 +22,26 @@ class MoviesCRUD(EntityCRUD[mdl.Movie]):
|
||||
async def change_actors(db: AsyncSession, movie: mdl.Movie, info: sch.MovieCreate):
|
||||
movie_actors = await MovieActorsCRUD.get_all(db)
|
||||
if (info.actors):
|
||||
actors_id = [actor.id for actor in info.actors]
|
||||
movie.actors = [
|
||||
actor for actor in movie_actors if actor.id in info.actors]
|
||||
actor for actor in movie_actors if actor.id in actors_id]
|
||||
|
||||
@staticmethod
|
||||
async def change_genres(db: AsyncSession, movie: mdl.Movie, info: sch.MovieCreate):
|
||||
movie_genres = await MovieGenresCRUD.get_all(db)
|
||||
if (info.genres):
|
||||
genres_id = [genre.id for genre in info.genres]
|
||||
movie.genres = [
|
||||
genre for genre in movie_genres if genre.id in info.genres]
|
||||
genre for genre in movie_genres if genre.id in genres_id]
|
||||
|
||||
@staticmethod
|
||||
async def add(db: AsyncSession,
|
||||
info: sch.MovieCreate,
|
||||
owner_id: int):
|
||||
movie = mdl.Movie(**info.model_dump(),
|
||||
movie_data_db = \
|
||||
{k: v for k, v in info.model_dump().items()
|
||||
if not k in ["actors", "genres", "update_date"]}
|
||||
movie = mdl.Movie(**movie_data_db,
|
||||
update_date=strftime("%Y-%m-%d %H:%M:%S"),
|
||||
owner_id=owner_id)
|
||||
await MoviesCRUD.change_genres(db, movie, info)
|
||||
|
||||
@@ -40,17 +40,17 @@ class AudiobookBase(AudiobookCardBase):
|
||||
duration: Optional[str] = Field(default=None, examples=["12:38"])
|
||||
reader: Optional[str] = Field(default=None, examples=["Дмитрий Хазанович"])
|
||||
|
||||
genres: Optional[list[AudiobookGenre]] = Field()
|
||||
|
||||
|
||||
class AudiobookCreate(AudiobookBase):
|
||||
genres: Optional[list[int]] = Field(default=None, examples=[[1, 2]])
|
||||
...
|
||||
|
||||
|
||||
class Audiobook(AudiobookBase):
|
||||
id: int = Field(examples=[1])
|
||||
update_date: str = Field(examples=["2024-06-14 12:00:00"])
|
||||
|
||||
genres: list[AudiobookGenre] = Field()
|
||||
|
||||
owner: User = Field()
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -41,17 +41,17 @@ class GameBase(GameCardBase):
|
||||
release_date: Optional[str] = Field(default=None, examples=["2014"])
|
||||
download_size: Optional[str] = Field(default=None, examples=["80Mb"])
|
||||
|
||||
genres: Optional[list[GameGenre]] = Field()
|
||||
|
||||
|
||||
class GameCreate(GameBase):
|
||||
genres: Optional[list[int]] = Field(default=None, examples=[[1, 2]])
|
||||
...
|
||||
|
||||
|
||||
class Game(GameBase):
|
||||
id: int = Field(examples=[1])
|
||||
update_date: str = Field(examples=["2024-05-13 12:00:00"])
|
||||
|
||||
genres: list[GameGenre] = Field()
|
||||
|
||||
owner: User = Field()
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -45,19 +45,18 @@ class MovieBase(MovieCardBase):
|
||||
country: Optional[str] = \
|
||||
Field(default=None, examples=["США, Великобритания, Канада"])
|
||||
|
||||
genres: Optional[list[MovieGenre]] = Field()
|
||||
actors: Optional[list[MovieActor]] = Field()
|
||||
|
||||
|
||||
class MovieCreate(MovieBase):
|
||||
genres: Optional[list[int]] = Field(default=None, examples=[[1, 2]])
|
||||
actors: Optional[list[int]] = Field(default=None, examples=[[1, 2]])
|
||||
...
|
||||
|
||||
|
||||
class Movie(MovieBase):
|
||||
id: int = Field(examples=[1])
|
||||
update_date: str = Field(examples=["2024-06-11 12:00:00"])
|
||||
|
||||
genres: list[MovieGenre] = Field()
|
||||
actors: list[MovieActor] = Field()
|
||||
|
||||
owner: User = Field()
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
Reference in New Issue
Block a user