Migrated links, lyrics and properties
This commit is contained in:
@@ -7,8 +7,10 @@ from folkugat_web.model import temes as model
|
||||
|
||||
|
||||
def create_tema(title: str = "") -> model.Tema:
|
||||
new_tema = model.Tema(title=title, hidden=False).with_ngrams()
|
||||
return temes_w.insert_tema(tema=new_tema)
|
||||
with get_connection() as con:
|
||||
new_tema = temes_w.insert_tema(tema=model.Tema(title=title, hidden=False), con=con)
|
||||
temes_w.update_ngrams(tema=new_tema, con=con)
|
||||
return new_tema
|
||||
|
||||
|
||||
def delete_tema(tema_id: int) -> None:
|
||||
@@ -21,131 +23,13 @@ def update_title(tema_id: int, title: str) -> model.Tema:
|
||||
if tema is None:
|
||||
raise ValueError(f"No tune found with tema_id = {tema_id}!")
|
||||
|
||||
new_tema = dataclasses.replace(tema, title=title).with_ngrams()
|
||||
new_tema = dataclasses.replace(tema, title=title)
|
||||
temes_w.update_tema(tema=new_tema, con=con)
|
||||
temes_w.update_ngrams(tema=new_tema, con=con)
|
||||
|
||||
return new_tema
|
||||
|
||||
|
||||
def update_lyric(tema_id: int, lyric_id: int, lyric: model.Lyrics) -> 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.lyrics.replace(lyric_id, lyric)
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def delete_lyric(tema_id: int, lyric_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.lyrics.delete(lyric_id)
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def add_lyric(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.lyrics.append(model.Lyrics(
|
||||
id=None,
|
||||
title=tema.title,
|
||||
content="",
|
||||
))
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def update_link(tema_id: int, link_id: int, link: model.Link) -> 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.links.replace(link_id, link)
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def delete_link(tema_id: int, link_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.links.delete(link_id)
|
||||
temes_w.update_tema(tema=tema, con=con)
|
||||
|
||||
return tema
|
||||
|
||||
|
||||
def add_link(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.links.append(model.Link(
|
||||
id=None,
|
||||
title="",
|
||||
url="",
|
||||
content_type=model.ContentType.OTHER,
|
||||
link_type=None,
|
||||
))
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user