listview done
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-11-26 03:21:08 +01:00
parent ed08fd3cbb
commit 95be4734a8
3 changed files with 36 additions and 4 deletions

View File

@ -12,7 +12,7 @@ services:
- ONSPOT_REDIS_URL="redis://db:6379/0" - ONSPOT_REDIS_URL="redis://db:6379/0"
- ONSPOT_ENCODED_SECRET_KEY="emdlc2RmYnZoa2xyYWl3ZmJkdmtzZ2Vhd2ZiaWx2a3M=" - ONSPOT_ENCODED_SECRET_KEY="emdlc2RmYnZoa2xyYWl3ZmJkdmtzZ2Vhd2ZiaWx2a3M="
ports: ports:
- "127.0.0.1:6379:6379" - "127.0.0.1:8080:8080"
networks: networks:
- backend - backend
db: db:

View File

@ -14,7 +14,7 @@ __version__text__ = "1"
def get_standard_error_handler(code: int): def get_standard_error_handler(code: int):
def error_handler(err): def error_handler(err):
musicbrainzngs.user(None, None) musicbrainzngs.auth(None, None)
return {"msg": str(err)}, code return {"msg": str(err)}, code
return error_handler return error_handler

View File

@ -41,7 +41,7 @@ class LoginApi(Resource):
try: try:
musicbrainzngs.auth(userobj['name'], userobj['password']) musicbrainzngs.auth(userobj['name'], userobj['password'])
musicbrainzngs.get_collections() print(musicbrainzngs.get_collections())
musicbrainzngs.auth(None, None) musicbrainzngs.auth(None, None)
except Exception as e: except Exception as e:
current_app.logger.warning(e) current_app.logger.warning(e)
@ -87,14 +87,45 @@ class ListsApi(Resource):
""" """
See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getAllLists See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getAllLists
""" """
encryptor = EncryptedUserRedis(ENCODED_SECRET_KEY)
def get(self): 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): class SingleListApi(Resource):
""" """
See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getList See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getList
""" """
def get(self, listid: str): def get(self, listid: str):
pass pass
@ -103,5 +134,6 @@ class TrackApi(Resource):
""" """
See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getTrack See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getTrack
""" """
def get(self, listid: str, trackid: str): def get(self, listid: str, trackid: str):
pass pass