modify last updated date of a playlist on track added

This commit is contained in:
geoffrey45
2023-01-13 20:58:10 +03:00
parent 198957bcae
commit b404933f89
2 changed files with 11 additions and 2 deletions
+1
View File
@@ -97,6 +97,7 @@ def add_track_to_playlist(playlist_id: str):
return {"error": "Track already exists in playlist"}, 409
add_artist_to_playlist(int(playlist_id), trackhash)
PL.update_last_updated(playlist_id)
return {"msg": "Done"}, 200
+10 -2
View File
@@ -4,7 +4,7 @@ from collections import OrderedDict
from app.db.sqlite.tracks import SQLiteTrackMethods
from app.db.sqlite.utils import SQLiteManager, tuple_to_playlist, tuples_to_playlists
from app.models import Artist
from app.utils import background
from app.utils import background, create_new_date
class SQLitePlaylistMethods:
@@ -156,7 +156,7 @@ class SQLitePlaylistMethods:
del playlist["id"]
del playlist["trackhashes"]
del playlist["artisthashes"]
del playlist['banner_pos']
del playlist["banner_pos"]
playlist = OrderedDict(sorted(playlist.items()))
params = (*playlist.values(), playlist_id)
@@ -164,6 +164,14 @@ class SQLitePlaylistMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, params)
@staticmethod
def update_last_updated(playlist_id: int, date=create_new_date()):
"""Updates the last updated date of a playlist."""
sql = """UPDATE playlists SET last_updated = ? WHERE id = ?"""
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (date, playlist_id))
@staticmethod
def delete_playlist(pid: str):
sql = "DELETE FROM playlists WHERE id = ?"