refactor most things to use the database directly

This commit is contained in:
geoffrey45
2022-06-13 14:45:18 +03:00
parent f1ec6309ba
commit 030ab8a379
18 changed files with 237 additions and 365 deletions
+15 -16
View File
@@ -18,12 +18,8 @@ class Playlists(MongoPlaylists):
Inserts a new playlist object into the database.
"""
return self.collection.update_one(
{
"name": playlist["name"]
},
{
"$set": playlist
},
{"name": playlist["name"]},
{"$set": playlist},
upsert=True,
).upserted_id
@@ -41,25 +37,28 @@ class Playlists(MongoPlaylists):
playlist = self.collection.find_one({"_id": ObjectId(id)})
return convert_one(playlist)
def add_track_to_playlist(self, playlistid: str, track: dict) -> None:
def set_last_updated(self, playlistid: str) -> None:
"""
Adds a track to a playlist.
Sets the lastUpdated field to the current date.
"""
date = create_new_date()
return self.collection.update_one(
{"_id": ObjectId(playlistid)},
{"$set": {"lastUpdated": date}},
)
def add_track_to_playlist(self, playlistid: str, track: dict) -> None:
"""
Adds a track to a playlist.
"""
self.collection.update_one(
{
"_id": ObjectId(playlistid),
},
{
"$push": {
"pre_tracks": track
},
"$set": {
"lastUpdated": date
}
},
{"$push": {"pre_tracks": track}},
)
self.set_last_updated(playlistid)
def get_playlist_by_name(self, name: str) -> dict:
"""