def delete_playlist(id): """ Deletes a playlist""" logging.debug("{users_controller} BEGIN function delete_playlist()") if id is '': return RESP.response_400(message='The id parameter is empty!') try: playlist = CRUD.read_playlist_by_id(id) except Exception: return RESP.response_500(message='Database is down!') if playlist is None: return RESP.response_404(message='Playlist not found!') try: CRUD.delete_object(playlist) entries = CRUD.read_songs_from_playlist(id) for entry in entries: CRUD.delete_object(entry) CRUD.commit() except Exception: CRUD.rollback() RESP.response_500(message='Database is down!') return RESP.response_200(message='Playlist deleted with success')
def delete_song_from_playlist(id, song_id, user_id): """ Removes a song from a playlist""" logging.debug( "{users_controller} BEGIN function delete_song_from_playlist()") if id is '' or song_id is '' or user_id is '': return RESP.response_400(message='A given parameter is empty') try: playlist = CRUD.read_playlist_by_id(id) except Exception: return RESP.response_500(message='Database is down!') if playlist is None: return RESP.response_404(message='Playlist not found!') if playlist.user_id != user_id: return RESP.response_400( message='This playlist belongs to another user') try: playlist_song = CRUD.read_song_from_playlist(id, song_id) except Exception: return RESP.response_500(message='Database is down!') if playlist_song is None: return RESP.response_404(message='Song not found is playlist') try: CRUD.delete_object(playlist_song) CRUD.commit() except Exception: CRUD.rollback() return RESP.response_500(message='Database is down!') return RESP.response_200(message='Song removed from playlist with success')