1
This commit is contained in:
@@ -154,6 +154,14 @@ class KnowledgeManager:
|
||||
raise ValueError("Materia no encontrada")
|
||||
return dict(row)
|
||||
|
||||
def update_subject(self, subject_id: int, name: str) -> dict[str, Any]:
|
||||
if not name.strip():
|
||||
raise ValueError("El nombre de la materia no puede estar vacio")
|
||||
self.get_subject(subject_id)
|
||||
with self._connect() as conn:
|
||||
conn.execute("update subjects set name = ? where id = ?", (name.strip(), subject_id))
|
||||
return self.get_subject(subject_id)
|
||||
|
||||
def delete_subject(self, subject_id: int) -> None:
|
||||
subject = self.get_subject(subject_id)
|
||||
with self._connect() as conn:
|
||||
@@ -224,6 +232,8 @@ class KnowledgeManager:
|
||||
def update_week(self, subject_id: int, current_number: int, new_number: int, title: str | None = None) -> dict[str, Any]:
|
||||
subject = self.get_subject(subject_id)
|
||||
week = self.get_week(subject_id, current_number)
|
||||
old_dir: Path | None = None
|
||||
new_dir: Path | None = None
|
||||
if new_number != current_number:
|
||||
with self._connect() as conn:
|
||||
existing = conn.execute(
|
||||
@@ -248,6 +258,22 @@ class KnowledgeManager:
|
||||
"update weeks set number = ?, title = ? where id = ?",
|
||||
(new_number, title, week["id"]),
|
||||
)
|
||||
if old_dir and new_dir:
|
||||
old_prefix = str(old_dir)
|
||||
new_prefix = str(new_dir)
|
||||
conn.execute(
|
||||
"update sources set stored_path = replace(stored_path, ?, ?) where week_id = ? and stored_path like ?",
|
||||
(old_prefix, new_prefix, week["id"], f"{old_prefix}%"),
|
||||
)
|
||||
conn.execute(
|
||||
"""
|
||||
update documents
|
||||
set markdown_path = replace(markdown_path, ?, ?)
|
||||
where source_id in (select id from sources where week_id = ?)
|
||||
and markdown_path like ?
|
||||
""",
|
||||
(old_prefix, new_prefix, week["id"], f"{old_prefix}%"),
|
||||
)
|
||||
return self.get_week(subject_id, new_number)
|
||||
|
||||
def week_dir(self, subject_slug: str, week_number: int) -> Path:
|
||||
|
||||
Reference in New Issue
Block a user