Exemple #1
0
    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
Exemple #2
0
    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
Exemple #3
0
    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