From 18081401ed749a3f9ce5aab292dcee41bdf3530b Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 1 Jun 2019 23:42:35 -0500 Subject: [PATCH 1/3] First Commit Solution --- Retos/sesion3-reto1/Sesion3-reto1.js | 211 +++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 Retos/sesion3-reto1/Sesion3-reto1.js diff --git a/Retos/sesion3-reto1/Sesion3-reto1.js b/Retos/sesion3-reto1/Sesion3-reto1.js new file mode 100644 index 0000000..091d2f4 --- /dev/null +++ b/Retos/sesion3-reto1/Sesion3-reto1.js @@ -0,0 +1,211 @@ +//Clase de usuario de spotify +class User{ + constructor(name, lastName, email, password,profileImage, subscription){ + + this.idUser=Math.floor((Math.random() * 10) + 1); + 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); + + } + 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; + } +} + + + + + +//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(name,lastName,email,password,profileImage, subscription){ + Users.push(new User(name,lastName,email, password,profileImage, new Subscription(subscription.type, subscription.activationDate,subscription.expirationDate))) + }, + 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)); + + + }, + + updateDB: function(users,artists){ + + for(let i=0; i Date: Sat, 1 Jun 2019 23:56:32 -0500 Subject: [PATCH 2/3] add playlist to user --- Retos/sesion3-reto1/Sesion3-reto1.js | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Retos/sesion3-reto1/Sesion3-reto1.js b/Retos/sesion3-reto1/Sesion3-reto1.js index 091d2f4..be03958 100644 --- a/Retos/sesion3-reto1/Sesion3-reto1.js +++ b/Retos/sesion3-reto1/Sesion3-reto1.js @@ -1,14 +1,20 @@ //Clase de usuario de spotify class User{ - constructor(name, lastName, email, password,profileImage, subscription){ + constructor(id,name, lastName, email, password,profileImage, subscription,playlists){ - this.idUser=Math.floor((Math.random() * 10) + 1); + + 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.subscription=new Subscription(subscription.type,subscription.activationDate,subscription.expirationDate); + this.playlists=playlists; } getName(){ @@ -65,7 +71,7 @@ class PlayList{ constructor(id,name,songs){ this.id=id; this.name=name; - this.songs; + this.songs=songs; } } @@ -112,8 +118,8 @@ function Spotify(){ init:function(){ SpotifyDB = new db([],[]); }, - addUser: function(name,lastName,email,password,profileImage, subscription){ - Users.push(new User(name,lastName,email, password,profileImage, new Subscription(subscription.type, subscription.activationDate,subscription.expirationDate))) + 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)); @@ -136,6 +142,13 @@ function Spotify(){ 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){ @@ -185,18 +198,24 @@ spotifyInstance.addSong(4,"Te bote","https://www.youtube.com/watch?v=9jI-z9QN6g8 console.log(Songs); //Asocio las canciones a los artistas/albunes -//canciones de Yola +//canciones de Yola agregadas album spotifyInstance.addSongToAlbum(1,1,1);//Se añade la cancion cucaracha/Intantiles/yola spotifyInstance.addSongToAlbum(1,1,2); -//camcipmes de Bad Bunny +//canciones de Bad Bunny agregadas al album spotifyInstance.addSongToAlbum(2,1,3); spotifyInstance.addSongToAlbum(2,2,4); // Un usuario se registra en spotify -spotifyInstance.addUser("Hugo","Deudor", "hufedebe@gmail.com", "hackspace","https://static.thenounproject.com/png/363633-200.png", new Subscription("free","01/06/19","02/06/19")); +spotifyInstance.addUser(1,"Hugo","Deudor", "hufedebe@gmail.com", "hackspace","https://static.thenounproject.com/png/363633-200.png", new Subscription("free","01/06/19","02/06/19"),[]); + + + +//Creamos un playlist para el usuario HUgo +spotifyInstance.addPlayList(1,1,"Musica para estudiar",[]); +spotifyInstance.addPlayList(1,2,"Musica para tonear",[]); From f9f9fbd57d060c5711539e0df13daf86ca7d3cbd Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 1 Jun 2019 23:57:39 -0500 Subject: [PATCH 3/3] delete logs --- Retos/sesion3-reto1/Sesion3-reto1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Retos/sesion3-reto1/Sesion3-reto1.js b/Retos/sesion3-reto1/Sesion3-reto1.js index be03958..9c44ad2 100644 --- a/Retos/sesion3-reto1/Sesion3-reto1.js +++ b/Retos/sesion3-reto1/Sesion3-reto1.js @@ -195,7 +195,7 @@ spotifyInstance.addSong(3,"Mia","https://www.youtube.com/watch?v=OSUxrSe5GbI", [ spotifyInstance.addSong(4,"Te bote","https://www.youtube.com/watch?v=9jI-z9QN6g8", ["chill", "reggaeton"]); -console.log(Songs); +//console.log(Songs); //Asocio las canciones a los artistas/albunes //canciones de Yola agregadas album