31 lines
932 B
Python
31 lines
932 B
Python
from collections.abc import Iterable, Iterator
|
|
|
|
from folkugat_web.dal.sql.temes import lyrics as lyrics_dal
|
|
from folkugat_web.model import temes as model
|
|
|
|
|
|
def add_lyrics_to_tema(tema: model.Tema) -> model.Tema:
|
|
if tema.id is not None:
|
|
tema.lyrics = list(lyrics_dal.get_lyrics(tema_id=tema.id))
|
|
return tema
|
|
|
|
|
|
def add_lyrics_to_temes(temes: Iterable[model.Tema]) -> Iterator[model.Tema]:
|
|
return map(add_lyrics_to_tema, temes)
|
|
|
|
|
|
def get_lyric_by_id(lyric_id: int, tema_id: int | None = None) -> model.Lyrics | None:
|
|
return next(iter(lyrics_dal.get_lyrics(lyric_id=lyric_id, tema_id=tema_id)), None)
|
|
|
|
|
|
def update_lyric(lyric: model.Lyrics):
|
|
lyrics_dal.update_lyric(lyric=lyric)
|
|
|
|
|
|
def delete_lyric(lyric_id: int, tema_id: int | None = None):
|
|
lyrics_dal.delete_lyric(lyric_id=lyric_id, tema_id=tema_id)
|
|
|
|
|
|
def create_lyric(tema_id: int) -> model.Lyrics:
|
|
return lyrics_dal.create_lyric(tema_id=tema_id)
|