diff --git a/Retos/sesion3-reto1/Sesion3-reto1.js b/Retos/sesion3-reto1/Sesion3-reto1.js new file mode 100644 index 0000000..9c44ad2 --- /dev/null +++ b/Retos/sesion3-reto1/Sesion3-reto1.js @@ -0,0 +1,230 @@ +//Clase de usuario de spotify +class User{ + constructor(id,name, lastName, email, password,profileImage, subscription,playlists){ + + + if(!playlists){ + playlists=[]; + } + + this.id=id; + this.name=name; + this.lastName=lastName; + this.email=email; + this.password=password; + this.profileImage=profileImage; + this.subscription=new Subscription(subscription.type,subscription.activationDate,subscription.expirationDate); + this.playlists=playlists; + + } + getName(){ + return this.name; + } +} + +//Clase de Artista +class Artist{ + constructor(idArtist,name,country,albums){ + if(!albums){ + albums=[]; + + } + + + this.idArtist=idArtist; + this.name=name; + this.country = country; + this.albums=albums; + + } +} + + +class Album{ + + constructor(id,name, releaseDate, genre,songs){ + this.id=id; + this.name=name; + this.releaseDate=releaseDate; + this.genre=genre; + this.songs=songs; + + } + + +} + + + +class Song{ + constructor(id,name, urlMedia,tags){ + this.id=id; + this.name=name; + this.urlMedia=urlMedia; + this.tags=tags; + } +} + + +class PlayList{ + + constructor(id,name,songs){ + this.id=id; + this.name=name; + this.songs=songs; + } +} + + + + + +//Clase de subscripción que puede tener un usuario +class Subscription{ + constructor(type,activationDate,expirationDate){ + this.type=type; + this.activationDate=activationDate; + this.expirationDate=expirationDate; + } +} + + + +let SpotifyDB; +let Users=[]; +let Songs=[]; +let Artists=[]; + +class db{ + constructor(users,artists){ + + if(!artists){ + this.artists=artists; + }else if(!users){ + this.users=users; + }else{ + this.users=users; + this.artists=artists; + } + + + + + } +} + +function Spotify(){ + return{ + init:function(){ + SpotifyDB = new db([],[]); + }, + addUser: function(id,name,lastName,email,password,profileImage, subscription,playlists){ + Users.push(new User(id,name,lastName,email, password,profileImage, new Subscription(subscription.type, subscription.activationDate,subscription.expirationDate),playlists)) + }, + addSong: function(id,name, urlMedia, tags){ + Songs.push(new Song(id,name,urlMedia,tags)); + + }, + addArtist:function(id,name,country,albums){ + Artists.push(new Artist(id,name,country,albums)); + + }, + addAlbum:function(idArtist,id,name, releaseDate, genre,songs){ + let index = Artists.findIndex(x => x.idArtist === idArtist); + Artists[index].albums.push(new Album(id,name,releaseDate,genre,songs)) + }, + addSongToAlbum:function(idArtist,idAlbum,idSongs){ + let indexArtist = Artists.findIndex(x => x.idArtist === idArtist); + let indexAlbum = Artists[indexArtist].albums.findIndex(x => x.id === idAlbum); + + let tempSong = Songs[Songs.findIndex(x => x.id === idSongs)]; + + Artists[indexArtist].albums[indexAlbum].songs.push(new Song(tempSong.id,tempSong.name,tempSong.urlMedia,tempSong.tags)); + + + }, + addPlayList:function(idUser,idPlayList,name,songs){ + let indexUser = Users.findIndex(x=>x.id === idUser); + + Users[indexUser].playlists.push(new PlayList(idPlayList,name,songs)); + + + }, + + updateDB: function(users,artists){ + + for(let i=0; i