mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 20:30: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)
|
||||
|
||||
Reference in New Issue
Block a user