def track_update(id, user=None): # Updates a track track_fields = track_schema.load(request.json) track = Tracks.query.filter_by(id=id).update(track_fields) if not track: return abort(400) db.session.commit() return jsonify(track_schema.dump(track))
def track_delete(id, user=None): # Deletes a track track = Tracks.query.get(id) mood = Moods.query.get(id) if not track: return abort(400) db.session.delete(mood) db.session.delete(track) db.session.commit() return jsonify(track_schema.dump(track))
def track_delete(id): #Delete a track user_id = get_jwt_identity() user = User.query.get(user_id) if not user: return abort(401, description="Invalid user") track = Track.query.filter_by(id=id, user_id=user.id).first() if not track: return abort(400) db.session.delete(track) db.session.commit() return jsonify(track_schema.dump(track))
def track_create(): # Creates a track track_fields = track_schema.load(request.json) new_mood = Moods() db.session.add(new_mood) db.session.commit() new_track = Tracks() new_track.trackname = track_fields["trackname"] new_track.moods_id = new_mood.id new_track.trackurl = track_fields["trackurl"] db.session.add(new_track) db.session.commit() return jsonify(track_schema.dump(new_track))
def track_update(id): #Update a track track_fields = track_schema.load(request.json) user_id = get_jwt_identity() user = User.query.get(user_id) if not user: return abort(401, description="Invalid user") tracks = Track.query.filter_by(id=id) if tracks.count() != 1: return abort(401, description="Unauthorized to update this book") tracks.update(track_fields) db.session.commit() return jsonify(track_schema.dump(tracks[0]))
def track_create(): #Create a new track track_fields = track_schema.load(request.json) user_id = get_jwt_identity() user = User.query.get(user_id) if not user: return abort(401, description="Invalid user") new_track = Track() new_track.track_title = track_fields["track_title"] user.tracks.append(new_track) db.session.add(new_track) db.session.commit() return jsonify(track_schema.dump(new_track))
def track_show(id): #Return a single track track = Track.query.get(id) return jsonify(track_schema.dump(track))
def track_retrive(id): # Retrives single track return jsonify(track_schema.dump(Tracks.query.get(id)))