def post(self, id_event): event = EventModel.find_by_id(id_event) if event: parser = reqparse.RequestParser( ) # create parameters parser from request # define al input parameters need and its type parser.add_argument(n.NM, type=str, required=True, help="Artistic name of the artist") parser.add_argument(n.CTRY, type=str, required=True, help="Country nationality of the artist") parser.add_argument(n.GNR, type=str, required=True, help="Main genre of the artist") data = parser.parse_args() with lock.lock: artist = ArtistModel.find_by_name(data[n.NM]) if artist and artist.country == data[ n.CTRY] and artist.genre == data[n.GNR]: event.artists.append(artist) event.save_to_db() return event.json(), 200 else: return {n.MSG: "Artist not found"}, 409 else: return {n.MSG: "Event not found"}, 404
def put(self, artist_id): id = ArtistModel.find_by_id(artist_id) if not id: return {'message': 'No Such Artist Exist'}, 404 data = parser.parse_args() _date = id.created_at if ArtistModel.find_by_name(data['name']): return {'message': 'Artist with this name already exists'}, 403 updated_artist = ArtistModel( name=data['name'], created_at=_date.strftime("%Y-%m-%d %H:%M:%S") ) if not data['name'] or data['name'].isspace(): return {'message': 'Please Enter Artist Name'}, 400 try: artist = ArtistModel.find_by_id(artist_id) artist.name = data['name'] updated_artist.commit_db() return { 'message': 'Artist Has been Updated', 'ArtistDetails': { 'id': artist_id, 'name': data['name'], 'created_at': _date.strftime("%Y-%m-%d %H:%M:%S") } }, 200 except: return { 'message': 'Something went Wrong' }, 500
def post(self): parser = reqparse.RequestParser( ) # create parameters parser from request # define al input parameters need and its type parser.add_argument(n.NM, type=str, required=True, help="Artistic name of the artist") parser.add_argument(n.CTRY, type=str, required=True, help="Country nationality of the artist") parser.add_argument(n.GNR, type=str, required=True, help="Main genre of the artist") data = parser.parse_args() with lock.lock: if ArtistModel.find_by_name(data[n.NM]): return {n.MSG: "Artist already in the data base"}, 409 if data[n.GNR] not in genres: return {n.MSG: "Genre not allowed"}, 400 try: new_artist = ArtistModel(data[n.NM], data[n.CTRY], data[n.GNR]) new_artist.save_to_db() return new_artist.json(), 201 except: return {n.MSG: "Error Description"}, 500
def post(self): data = parser.parse_args() if ArtistModel.find_by_name(data['name']): return {'message': 'Artist with this Name Already Existed'}, 403 _created_at = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) new_artist = ArtistModel( name=data['name'], created_at=_created_at ) if not data['name'] or data['name'].isspace(): return {'message': 'Please Enter Artist Name'}, 400 try: new_artist.save_to_db() new_id = new_artist.id return { 'message': 'New Artist Has been Added', 'ArtistDetails': { 'id': new_id, 'name': data['name'], 'created_at': _created_at } }, 201 except: return { 'message': 'Something went Wrong' }, 500
def put(self, id): artist = ArtistModel.find_by_id(id) if artist: parser = reqparse.RequestParser( ) # create parameters parser from request # define al input parameters need and its type parser.add_argument(n.NM, type=str, required=True, help="Artistic name of the artist") parser.add_argument(n.CTRY, type=str, required=True, help="Country nationality of the artist") parser.add_argument(n.GNR, type=str, required=True, help="Main genre of the artist") data = parser.parse_args() with lock.lock: if data[n.GNR] not in genres: return {n.MSG: "Genre not allowed"}, 400 aux_artist = ArtistModel.find_by_name(data[n.NM]) if aux_artist and aux_artist.id != id: return { n.MSG: "Artist already in the data base with another ID" }, 409 try: artist.modify_from_db(data[n.NM], data[n.CTRY], data[n.GNR]) return artist.json(), 200 except: return {n.MSG: "Error Description"}, 500 else: return {n.MSG: "Artist not found"}, 404