Ejemplo n.º 1
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'
Ejemplo n.º 2
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'