Tune editor
This commit is contained in:
@@ -6,6 +6,14 @@ from folkugat_web.dal.sql.temes import write as temes_w
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
|
||||
def create_tema(title: str = "") -> model.Tema:
|
||||
return temes_w.insert_tema(tema=model.Tema(title=title))
|
||||
|
||||
|
||||
def delete_tema(tema_id: int) -> None:
|
||||
tema = temes_w.delete_tema(tema_id=tema_id)
|
||||
|
||||
|
||||
def update_title(tema_id: int, title: str) -> model.Tema:
|
||||
with get_connection() as con:
|
||||
tema = temes_q.get_tema_by_id(tema_id=tema_id, con=con)
|
||||
@@ -98,3 +106,53 @@ def add_link(tema_id: int) -> model.Tema:
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def update_property(tema_id: int, property_id: int, prop: model.Property) -> model.Tema:
|
||||
with get_connection() as con:
|
||||
tema = temes_q.get_tema_by_id(tema_id=tema_id, con=con)
|
||||
if tema is None:
|
||||
raise ValueError(f"No tune found with tema_id = {tema_id}!")
|
||||
|
||||
tema.properties.replace(property_id, prop)
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def delete_property(tema_id: int, property_id: int) -> model.Tema:
|
||||
with get_connection() as con:
|
||||
tema = temes_q.get_tema_by_id(tema_id=tema_id, con=con)
|
||||
if tema is None:
|
||||
raise ValueError(f"No tune found with tema_id = {tema_id}!")
|
||||
|
||||
tema.properties.delete(property_id)
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def add_property(tema_id: int) -> model.Tema:
|
||||
with get_connection() as con:
|
||||
tema = temes_q.get_tema_by_id(tema_id=tema_id, con=con)
|
||||
if tema is None:
|
||||
raise ValueError(f"No tune found with tema_id = {tema_id}!")
|
||||
tema.properties.append(model.Property(
|
||||
id=None,
|
||||
field=model.PropertyField.AUTOR,
|
||||
value="",
|
||||
))
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def set_visibility(tema_id: int, hidden: bool) -> model.Tema:
|
||||
with get_connection() as con:
|
||||
tema = temes_q.get_tema_by_id(tema_id=tema_id, con=con)
|
||||
if tema is None:
|
||||
raise ValueError(f"No tune found with tema_id = {tema_id}!")
|
||||
tema.hidden = hidden
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
Reference in New Issue
Block a user