Sync alternativer
This commit is contained in:
@@ -113,12 +113,13 @@ CREATE TABLE IF NOT EXISTS song_dances (
|
||||
|
||||
-- Alternativ-dans tags
|
||||
CREATE TABLE IF NOT EXISTS song_alt_dances (
|
||||
id TEXT PRIMARY KEY,
|
||||
song_id TEXT NOT NULL REFERENCES songs(id) ON DELETE CASCADE,
|
||||
dance_id INTEGER NOT NULL REFERENCES dances(id),
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
source TEXT NOT NULL DEFAULT 'local',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
id TEXT PRIMARY KEY,
|
||||
song_id TEXT NOT NULL REFERENCES songs(id) ON DELETE CASCADE,
|
||||
dance_id INTEGER NOT NULL REFERENCES dances(id),
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
user_rating INTEGER, -- 1-5 stjerner, NULL = ikke vurderet
|
||||
source TEXT NOT NULL DEFAULT 'local',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
UNIQUE(song_id, dance_id)
|
||||
);
|
||||
|
||||
@@ -140,14 +141,15 @@ CREATE TABLE IF NOT EXISTS playlists (
|
||||
|
||||
-- Playliste-sange
|
||||
CREATE TABLE IF NOT EXISTS playlist_songs (
|
||||
id TEXT PRIMARY KEY,
|
||||
playlist_id TEXT NOT NULL REFERENCES playlists(id) ON DELETE CASCADE,
|
||||
song_id TEXT NOT NULL REFERENCES songs(id),
|
||||
file_id TEXT REFERENCES files(id),
|
||||
position INTEGER NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
is_workshop INTEGER NOT NULL DEFAULT 0,
|
||||
dance_override TEXT NOT NULL DEFAULT ''
|
||||
id TEXT PRIMARY KEY,
|
||||
playlist_id TEXT NOT NULL REFERENCES playlists(id) ON DELETE CASCADE,
|
||||
song_id TEXT NOT NULL REFERENCES songs(id),
|
||||
file_id TEXT REFERENCES files(id),
|
||||
position INTEGER NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
is_workshop INTEGER NOT NULL DEFAULT 0,
|
||||
dance_override TEXT NOT NULL DEFAULT '',
|
||||
alt_dance_override TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_playlist_songs_playlist ON playlist_songs(playlist_id);
|
||||
@@ -692,4 +694,49 @@ def get_or_create_dance(name: str, level_id: int | None, conn,
|
||||
"INSERT INTO dances (name, level_id, choreographer) VALUES (?,?,?)",
|
||||
(name, level_id, choreo)
|
||||
)
|
||||
return cur.lastrowid
|
||||
return cur.lastrowid
|
||||
|
||||
def rate_alt_dance(song_id: str, dance_id: int, rating: int | None):
|
||||
"""Sæt brugerens rating (1-5) på en alternativ-dans. None = fjern rating."""
|
||||
with get_db() as conn:
|
||||
conn.execute(
|
||||
"UPDATE song_alt_dances SET user_rating=? WHERE song_id=? AND dance_id=?",
|
||||
(rating, song_id, dance_id)
|
||||
)
|
||||
|
||||
|
||||
def get_alt_dances_for_song_with_ratings(song_id: str) -> list:
|
||||
"""Hent alternativ-danse med bruger-rating og community-rating."""
|
||||
with get_db() as conn:
|
||||
rows = conn.execute("""
|
||||
SELECT d.id, d.name, d.level_id, dl.name as level_name,
|
||||
d.choreographer, sad.note, sad.user_rating,
|
||||
sad.source
|
||||
FROM song_alt_dances sad
|
||||
JOIN dances d ON d.id = sad.dance_id
|
||||
LEFT JOIN dance_levels dl ON dl.id = d.level_id
|
||||
WHERE sad.song_id = ?
|
||||
ORDER BY sad.user_rating DESC NULLS LAST, d.name
|
||||
""", (song_id,)).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
def get_community_alts_for_song(song_id: str) -> list:
|
||||
"""Hent community alternativ-danse for en sang med ratings."""
|
||||
with get_db() as conn:
|
||||
# Opret tabellen hvis den ikke eksisterer
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS community_alt_dances ("
|
||||
"id TEXT PRIMARY KEY, song_id TEXT NOT NULL, dance_id INTEGER NOT NULL, "
|
||||
"avg_rating REAL NOT NULL DEFAULT 0, rating_count INTEGER NOT NULL DEFAULT 0, "
|
||||
"my_rating INTEGER, UNIQUE(song_id, dance_id))"
|
||||
)
|
||||
rows = conn.execute("""
|
||||
SELECT d.id, d.name, dl.name as level_name, d.choreographer,
|
||||
cad.avg_rating, cad.rating_count, cad.my_rating
|
||||
FROM community_alt_dances cad
|
||||
JOIN dances d ON d.id = cad.dance_id
|
||||
LEFT JOIN dance_levels dl ON dl.id = d.level_id
|
||||
WHERE cad.song_id = ?
|
||||
ORDER BY cad.avg_rating DESC
|
||||
""", (song_id,)).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
Reference in New Issue
Block a user