Beispiel #1
0
	async def update_artist(artist_id: str, artist: ArtistEdition, username: str = auth):
		to_update = await mongo.find_one(artist_id, db_m)
		if to_update is not None:
			update_data = artist.dict(exclude_unset=True)
			update_model = Artist(**to_update).copy(update=update_data)
			result = await mongo.update_one(artist_id, classToDict(update_model), db_m)
			return result
		return 'Invalid Id'
Beispiel #2
0
 async def update_song(song_id: str,
                       song: SongEdition,
                       username: str = auth):
     to_update = await mongo.find_one(song_id, db_m)
     if to_update is not None:
         update_data = song.dict(exclude_unset=True)
         update_model = SongEdition(**to_update).copy(update=update_data)
         result = await mongo.update_one(song_id, classToDict(update_model),
                                         db_m)
         return result
     return 'Invalid Id'
Beispiel #3
0
	async def delete_artist_song(artist_id: str, song_id: str, username: str = auth):
		to_update = await mongo.find_one(artist_id, db_m)
		update_model = Artist(**to_update)
		if to_update is not None:
			if update_model.canciones is not None:
				cont=0
				canciones_to_update = []
				for c in update_model.canciones:
					if c.id != song_id:
						canciones_to_update.append(c)
						cont+=1
				if cont == len(update_model.canciones):
					return 'Invalid Id for Cancion'
				update_data = {'canciones': canciones_to_update}
				updated = update_model.copy(update=update_data)
				result = await mongo.update_one(artist_id, classToDict(updated), db_m)
				return result
			else:
				return 'Do not find Canciones'
		return 'Invalid Id for Artista'
Beispiel #4
0
	async def create_artist_song(artist_id: str, song: str, username: str = auth):
		to_update = await mongo.find_one(artist_id, db_m)
		update_model = Artist(**to_update)
		if to_update is not None:
			song_db = await mongo.find_many(update_model.nombre+' '+song, db_s)
			if song_db is not None:
				cancion = {
					'id': song_db[0]['id'],
					'cancion': song_db[0]['metadata']['cancion'],
					'album': song_db[0]['metadata']['album']
				}
				if update_model.canciones is not None:
					canciones_to_update = update_model.canciones
					canciones_to_update.append(ArtistSong(**cancion))
				else:
					canciones_to_update = []
					canciones_to_update.append(ArtistSong(**cancion))
				update_data = {'canciones': canciones_to_update}
				updated = update_model.copy(update=update_data)
				result = await mongo.update_one(artist_id, classToDict(updated), db_m)
				return result 
			return 'La canción no se encontró'
		return 'Invalid Id'
Beispiel #5
0
 async def replace_song(song_id: str, song: Song, username: str = auth):
     result = await mongo.replace_one(song_id, classToDict(song), db_m)
     return result
Beispiel #6
0
 async def create_many_song(songs: List[Song], username: str = auth):
     result = await mongo.insert_many([classToDict(song) for song in songs],
                                      db_m)
     return result
Beispiel #7
0
 async def create_song(song: Song, username: str = auth):
     result = await mongo.insert_one(classToDict(song), db_m)
     return result
Beispiel #8
0
	async def replace_artist(artist_id: str, artist: Artist, username: str = auth):
		result = await mongo.replace_one(artist_id, classToDict(artist), db_m)
		return result
Beispiel #9
0
	async def create_many_artist(artists: List[Artist], username: str = auth):
		result = await mongo.insert_many([classToDict(artist) for artist in artists], db_m)
		return result
Beispiel #10
0
	async def create_artist(artist: Artist, username: str = auth):
		result = await mongo.insert_one(classToDict(artist), db_m)
		return result