From 95be4734a87ed5173a511249c7f21de36c277ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 26 Nov 2020 03:21:08 +0100 Subject: [PATCH] listview done --- docker-compose.yml | 2 +- src/errorhandlers.py | 2 +- src/resources.py | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index eef9772..b43074c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - ONSPOT_REDIS_URL="redis://db:6379/0" - ONSPOT_ENCODED_SECRET_KEY="emdlc2RmYnZoa2xyYWl3ZmJkdmtzZ2Vhd2ZiaWx2a3M=" ports: - - "127.0.0.1:6379:6379" + - "127.0.0.1:8080:8080" networks: - backend db: diff --git a/src/errorhandlers.py b/src/errorhandlers.py index 0ad3b73..e734b63 100644 --- a/src/errorhandlers.py +++ b/src/errorhandlers.py @@ -14,7 +14,7 @@ __version__text__ = "1" def get_standard_error_handler(code: int): def error_handler(err): - musicbrainzngs.user(None, None) + musicbrainzngs.auth(None, None) return {"msg": str(err)}, code return error_handler diff --git a/src/resources.py b/src/resources.py index 47143ed..81743cf 100644 --- a/src/resources.py +++ b/src/resources.py @@ -41,7 +41,7 @@ class LoginApi(Resource): try: musicbrainzngs.auth(userobj['name'], userobj['password']) - musicbrainzngs.get_collections() + print(musicbrainzngs.get_collections()) musicbrainzngs.auth(None, None) except Exception as e: current_app.logger.warning(e) @@ -87,14 +87,45 @@ class ListsApi(Resource): """ See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getAllLists """ + encryptor = EncryptedUserRedis(ENCODED_SECRET_KEY) + def get(self): - pass + try: + currcreds = self.encryptor.load(flaskred.get(request.headers.get('Authorization')).decode('UTF-8')) + except Exception as e: + current_app.logger.warning(e) + abort(401, "unauthorized") + + musicbrainzngs.auth(currcreds['name'], currcreds['password']) + collections = musicbrainzngs.get_collections() + musicbrainzngs.auth(None, None) + elementlist = [] + for collection in collections['collection-list']: + if collection['entity-type'] == 'release': + count = collection['release-count'] + elif collection['entity-type'] == 'artist': + count = collection['artist-count'] + elif collection['entity-type'] == 'work': + count = collection['work-count'] + elif collection['entity-type'] == 'recording': + count = collection['recording-count'] + elif collection['entity-type'] == 'release_group': + elementlist.append({"id": collection['id'], "name": collection['name']}) + continue + else: + continue + elementlist.append({"id": collection['id'], "name": collection['name'], "element_count": count}) + returndict = {"count": collections['collection-count'], + "ids": elementlist} + + return returndict, 200 class SingleListApi(Resource): """ See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getList """ + def get(self, listid: str): pass @@ -103,5 +134,6 @@ class TrackApi(Resource): """ See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getTrack """ + def get(self, listid: str, trackid: str): pass