refactor media and database handling to replace 'filename' with 'media_path' for consistency

This commit is contained in:
2025-09-07 20:00:05 +02:00
parent 46af4e8588
commit cfea46c653
2 changed files with 8 additions and 8 deletions

View File

@@ -49,7 +49,7 @@ class DatabaseManager:
CREATE TABLE IF NOT EXISTS media (
id INTEGER PRIMARY KEY AUTOINCREMENT,
color_id INTEGER NOT NULL,
filename TEXT NOT NULL,
media_path TEXT NOT NULL,
file_type TEXT CHECK(file_type IN ('photo','video')),
timestamp TEXT DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(color_id) REFERENCES colors(id) ON DELETE CASCADE
@@ -112,7 +112,7 @@ class DatabaseManager:
# -------------------------
# Operacje na plikach
# -------------------------
def add_media(self, color_id: int, filename: str, file_type: str, timestamp: str | None = None):
def add_media(self, color_id: int, media_path: str, file_type: str, timestamp: str | None = None):
if timestamp is None:
timestamp = datetime.now().isoformat()
@@ -120,8 +120,8 @@ class DatabaseManager:
raise RuntimeError("Database not connected")
cur = self.conn.cursor()
cur.execute(
"INSERT INTO media (color_id, filename, file_type, timestamp) VALUES (?, ?, ?, ?)",
(color_id, filename, file_type, timestamp),
"INSERT INTO media (color_id, media_path, file_type, timestamp) VALUES (?, ?, ?, ?)",
(color_id, media_path, file_type, timestamp),
)
self.conn.commit()
@@ -133,11 +133,11 @@ class DatabaseManager:
rows = cur.fetchall()
return [dict(r) for r in rows]
def delete_media(self, color_id: int, filename: str):
def delete_media(self, color_id: int, media_path: str):
if self.conn is None:
raise RuntimeError("Database not connected")
cur = self.conn.cursor()
cur.execute("DELETE FROM media WHERE color_id = ? AND filename = ?", (color_id, filename))
cur.execute("DELETE FROM media WHERE color_id = ? AND media_path = ?", (color_id, media_path))
self.conn.commit()
def delete_all_media_for_color(self, color_id: int):