def create_playlist(): data = request.json try: playlist = Playlist(name=data['playlistName'], user_id=data['id']) db.session.add(playlist) db.session.commit() return {'playlist': playlist.to_dict()} except AssertionError as message: return jsonify({"error": str(message)}), 400
def addToPlaylist(): data = request.json playlist = Playlist( name=data['name'], song_id=data['songId'], user_id=data['userId'], ) db.session.add(playlist) db.session.commit() playlists = Playlist.query.filter_by(user_id=data['userId']).all() playlistList = [] for playlist in playlists: playlist_id = playlist.id playlist_dict = playlist.to_dict() # playlist_dict['playlist_id'] = playlist_id playlistList.append(playlist_dict) return jsonify(playlistList)
def addPlaylist(): data = request.json # form = PlaylistForm() # form['csrf_token'].data = request.cookies['csrf_token'] playlist = Playlist( name=data['name'], user_id=data['userId'], song_id=None, ) db.session.add(playlist) db.session.commit() playlists = Playlist.query.filter_by(user_id=data['userId']).all() playlistList = [] for playlist in playlists: playlist_id = playlist.id playlist_dict = playlist.to_dict() # playlist_dict['playlist_id'] = playlist_id playlistList.append(playlist_dict) return jsonify(playlistList)