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
+11 -10
View File
@@ -21,16 +21,17 @@ class Albums(MongoAlbums):
"""
album = album.__dict__
return self.collection.update_one(
{
"album": album["title"],
"artist": album["artist"]
},
{
"$set": album
},
{"album": album["title"], "artist": album["artist"]},
{"$set": album},
upsert=True,
).upserted_id
def insert_many(self, albums: list):
"""
Inserts multiple albums into the database.
"""
return self.collection.insert_many(albums)
def get_all_albums(self) -> list:
"""
Returns all the albums in the database.
@@ -52,9 +53,9 @@ class Albums(MongoAlbums):
album = self.collection.find_one({"album": name, "artist": artist})
return convert_one(album)
def get_album_by_artist(self, name: str) -> dict:
def find_album_by_hash(self, hash: str) -> dict:
"""
Returns a single album matching the artist in the query params.
Returns a single album matching the hash in the query params.
"""
album = self.collection.find_one({"albumartist": name})
album = self.collection.find_one({"hash": hash})
return convert_one(album)