def get(self): args = auth_parser.parse_args() artist = authentication_header_parser(args['Authorization']) artist_albums = (AlbumModel.query.filter_by( artist_id=artist['id']).order_by('id').all()) return artist_albums
def get(self, album_id): args = auth_parser.parse_args() artist = authentication_header_parser(args['Authorization']) artist_album = (AlbumModel.query.filter_by( id=album_id, artist_id=artist['id']).first()) if not artist_album: return '', http.client.NOT_FOUND return artist_album
def delete(self, song_id): args = auth_parser.parse_args() artist = authentication_header_parser(args['Authorization']) artist_song = (SongModel.query.filter_by( id=song_id, artist_id=artist['id']).first()) if artist_song: db.session.delete(artist_song) db.session.commit() return '', http.client.NO_CONTENT
def delete(self, album_id): args = auth_parser.parse_args() artist = authentication_header_parser(args['Authorization']) artist_album = (AlbumModel.query.filter_by( id=album_id, artist_id=artist['id']).first()) if not artist_album: return '', http.client.NOT_FOUND db.session.delete(artist_album) db.session.commit() return '', http.client.NO_CONTENT
def patch(self, album_id): args = album_parser.parse_args() artist = authentication_header_parser(args['Authorization']) artist_album = (AlbumModel.query.filter_by( id=album_id, artist_id=artist['id']).first()) if not artist_album: return '', http.client.NOT_FOUND for key, val in args.items(): if hasattr(artist_album, key): setattr(artist_album, key, val) db.session.commit() result = api_namespace.marshal(artist_album, album_model) return result, http.client.OK
def post(self): args = album_parser.parse_args() artist = authentication_header_parser(args['Authorization']) if args['price'] < 0: return '', http.client.BAD_REQUEST new_album = AlbumModel(name=args['name'], price=args['price'], genre=args['genre'], date=datetime.utcnow(), description=args['description'], artist_name=artist['name'], artist_id=artist['id']) db.session.add(new_album) db.session.commit() result = api_namespace.marshal(new_album, album_model) return result, http.client.CREATED
def post(self, album_id): args = song_parser.parse_args() artist = authentication_header_parser(args['Authorization']) artist_album = (AlbumModel.query.filter_by(artist_id=artist['id'], id=album_id).first()) if not artist_album: return '', http.client.NOT_FOUND new_song = SongModel(name=args['name'], artist_name=artist['name'], artist_id=artist['id'], album_id=album_id) db.session.add(new_song) db.session.commit() result = api_namespace.marshal(new_song, song_model) return result, http.client.CREATED