From 6b4916e898e90f43bd5b6ccdf72d2a1da7623b4a Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE Date: Sun, 21 May 2023 22:04:10 +0200 Subject: [PATCH] Fix Equals class, now it compares the Name, not the ImageURL anymore --- Sources/Model/Album.cs | 2 +- Sources/Model/IDataManager.cs | 22 +++--- Sources/Model/InfoTitle.cs | 2 +- Sources/Model/Manager.cs | 4 +- .../Serialization/LINQ_XML_Serialization.cs | 57 +++++++--------- Sources/Model/Stub/StubManager.cs | 67 ++++++++++++------- 6 files changed, 83 insertions(+), 71 deletions(-) diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 3512f0a..84e1454 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -116,7 +116,7 @@ namespace Model { if (obj is null) return false; if (obj.GetType() != typeof(Album)) return false; - if (obj is Album album && ImageURL == album.ImageURL) return true; + if (obj is Album album && Name == album.Name) return true; else return false; } diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 179d610..7db21e1 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -32,11 +32,11 @@ public interface IDataManager ObservableCollection GetInfoTitles(); - InfoTitle? GetInfoTitleByUrl(string url); + InfoTitle? GetInfoTitleByName(string name); ObservableCollection GetAlbums(); - Album? GetAlbumByUrl(string url); + Album? GetAlbumByName(string name); List GetArtists(); @@ -44,7 +44,7 @@ public interface IDataManager ObservableCollection GetPlaylists(); - Playlist? GetPlaylistByUrl(string url); + Playlist? GetPlaylistByName(string name); // Update @@ -54,23 +54,23 @@ public interface IDataManager void UpdateInfoTitle(InfoTitle title, string name, string url, string info, Artist artist, string description, Genre genre); - void UpdateInfoTitleByName(string url, string name, string newUrl, string info, Artist artist, string description, Genre genre); + void UpdateInfoTitleByName(string name, string newUrl, string info, Artist artist, string description, Genre genre); void UpdateInfoTitleByArtistName(InfoTitle title, string name, string url, string info, string artist, string description, Genre genre); - void UpdateInfoTitleByNameByArtistName(string url, string name, string newUrl, string info, string artist, string description, Genre genre); + void UpdateInfoTitleByNameByArtistName(string name, string newUrl, string info, string artist, string description, Genre genre); void UpdateAlbum(Album album, string name, string url, Artist artist, string description, string info); - void UpdateAlbumByUrl(string url, string name, string newUrl, Artist artist, string description, string info); + void UpdateAlbumByName(string name, string newUrl, Artist artist, string description, string info); void UpdateAlbumByArtistName(Album album, string name, string url, string artist, string description, string info); - void UpdateAlbumByUrlByArtistName(string url, string name, string newUrl, string artist, string description, string info); + void UpdateAlbumByNameByArtistName(string name, string newUrl, string artist, string description, string info); void UpdatePlaylist(Playlist playlist, string name, string description, string url); - void UpdatePlaylistByUrl(string url, string name, string description, string newUrl); + void UpdatePlaylistByName(string name, string description, string newUrl); void UpdateArtist(Artist artist, string name); @@ -105,11 +105,11 @@ public interface IDataManager // Exists bool ExistsPlaylist(Playlist playlist); - bool ExistsPlaylistByUrl(string url); + bool ExistsPlaylistByName(string name); bool ExistsAlbum(Album album); - bool ExistsAlbumByUrl(string url); + bool ExistsAlbumByName(string name); bool ExistsArtist(Artist artist); @@ -121,5 +121,5 @@ public interface IDataManager bool ExistsInfoTitle(InfoTitle title); - bool ExistsInfoTitleByUrl(string url); + bool ExistsInfoTitleByName(string name); } \ No newline at end of file diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index 2330477..8a4b714 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -62,7 +62,7 @@ public class InfoTitle : Title { if (obj is null) return false; if (obj.GetType() != typeof(InfoTitle)) return false; - if (obj is InfoTitle infoTitle && ImageURL == infoTitle.ImageURL) return true; + if (obj is InfoTitle infoTitle && Name == infoTitle.Name) return true; else return false; } diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 28edf34..c5ef903 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -166,9 +166,9 @@ public class Manager DataManager.SaveSerialization(); } - public Playlist? GetPlaylistByUrl(string url) + public Playlist? GetPlaylistByName(string name) { - return DataManager.GetPlaylistByUrl(url); + return DataManager.GetPlaylistByName(name); } } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index da9fe64..414ef7e 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -1,15 +1,6 @@ -using Model.Stub; -using System.Diagnostics.Metrics; -using System; -using System.Linq; -using System.Xml; +using System.Xml; using System.Xml.Linq; -using System.Xml.Serialization; -using static System.Reflection.Metadata.BlobBuilder; -using System.Reflection.Metadata; -using System.IO; using System.Collections.ObjectModel; -using System.Reflection.Emit; namespace Model.Serialization; @@ -460,7 +451,7 @@ public class LinqXmlSerialization : IDataManager continue; } - InfoTitle? infoTitle = GetInfoTitleByUrl(title); + InfoTitle? infoTitle = GetInfoTitleByName(title); if (infoTitle == null) { @@ -607,11 +598,11 @@ public class LinqXmlSerialization : IDataManager else return Genre.K_POP; } - public InfoTitle? GetInfoTitleByUrl(string url) + public InfoTitle? GetInfoTitleByName(string name) { foreach(InfoTitle it in infoTitles) { - if (it.Name == url) + if (it.Name == name) { return it; } @@ -631,11 +622,11 @@ public class LinqXmlSerialization : IDataManager return null; } - public Album? GetAlbumByUrl(string url) + public Album? GetAlbumByName(string name) { foreach(Album a in albums) { - if (a.ImageURL == url) + if (a.Name == name) { return a; } @@ -695,11 +686,11 @@ public class LinqXmlSerialization : IDataManager } } - public Playlist? GetPlaylistByUrl(string url) + public Playlist? GetPlaylistByName(string name) { foreach(Playlist p in playlists) { - if (p.ImageURL == url) + if (p.Name == name) { return p; } @@ -737,9 +728,9 @@ public class LinqXmlSerialization : IDataManager title.Genre = genre; } - public void UpdateInfoTitleByName(string url, string name, string newUrl, string info, Artist artist, string description, Genre genre) + public void UpdateInfoTitleByName(string name, string newUrl, string info, Artist artist, string description, Genre genre) { - InfoTitle? title = GetInfoTitleByUrl(url); + InfoTitle? title = GetInfoTitleByName(name); if (title != null) { title.Name = name; @@ -765,9 +756,9 @@ public class LinqXmlSerialization : IDataManager title.Genre = genre; } - public void UpdateInfoTitleByNameByArtistName(string url, string name, string newUrl, string info, string artist, string description, Genre genre) + public void UpdateInfoTitleByNameByArtistName(string name, string newUrl, string info, string artist, string description, Genre genre) { - InfoTitle? title = GetInfoTitleByUrl(url); + InfoTitle? title = GetInfoTitleByName(name); if (title != null) { title.Name = name; @@ -792,9 +783,9 @@ public class LinqXmlSerialization : IDataManager album.Information = info; } - public void UpdateAlbumByUrl(string url, string name, string newUrl, Artist artist, string description, string info) + public void UpdateAlbumByName(string name, string newUrl, Artist artist, string description, string info) { - Album? album = GetAlbumByUrl(url); + Album? album = GetAlbumByName(name); if (album != null) { album.Name = name; @@ -818,9 +809,9 @@ public class LinqXmlSerialization : IDataManager album.Information = info; } - public void UpdateAlbumByUrlByArtistName(string url, string name, string newUrl, string artist, string description, string info) + public void UpdateAlbumByNameByArtistName(string name, string newUrl, string artist, string description, string info) { - Album? album = GetAlbumByUrl(url); + Album? album = GetAlbumByName(name); if (album != null) { album.Name = name; @@ -842,9 +833,9 @@ public class LinqXmlSerialization : IDataManager playlist.ImageURL = url; } - public void UpdatePlaylistByUrl(string url, string name, string description, string newUrl) + public void UpdatePlaylistByName(string name, string description, string newUrl) { - Playlist? playlist = GetPlaylistByUrl(url); + Playlist? playlist = GetPlaylistByName(name); if (playlist != null) { playlist.Name = name; @@ -919,11 +910,11 @@ public class LinqXmlSerialization : IDataManager return false; } - public bool ExistsPlaylistByUrl(string url) + public bool ExistsPlaylistByName(string name) { foreach(Playlist p in playlists) { - if (p.ImageURL == url) + if (p.Name == name) { return true; } @@ -943,11 +934,11 @@ public class LinqXmlSerialization : IDataManager return false; } - public bool ExistsAlbumByUrl(string url) + public bool ExistsAlbumByName(string name) { foreach(Album a in albums) { - if (a.ImageURL == url) + if (a.Name == name) { return true; } @@ -1015,11 +1006,11 @@ public class LinqXmlSerialization : IDataManager return false; } - public bool ExistsInfoTitleByUrl(string url) + public bool ExistsInfoTitleByName(string name) { foreach(InfoTitle it in infoTitles) { - if(it.ImageURL == url) + if(it.Name == name) { return true; } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 5ffc50b..8a60249 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -170,19 +170,40 @@ public class StubManager : IDataManager return null; } - public InfoTitle? GetInfoTitleByUrl(string url) + public InfoTitle? GetInfoTitleByName(string name) { - throw new NotImplementedException(); + foreach(InfoTitle title in StubInfoTitle.GetInfoTitles()) + { + if (title.Name == name) + { + return title; + } + } + return null; } - public Album? GetAlbumByUrl(string url) + public Album? GetAlbumByName(string name) { - throw new NotImplementedException(); + foreach(Album album in StubAlbum.GetAlbums()) + { + if (album.Name == name) + { + return album; + } + } + return null; } public Artist? GetArtistByName(string name) { - throw new NotImplementedException(); + foreach(Artist artist in StubArtist.GetArtists()) + { + if (artist.Name == name) + { + return artist; + } + } + return null; } public void AddAlbums(List albumsList) @@ -225,11 +246,11 @@ public class StubManager : IDataManager } } - public Playlist? GetPlaylistByUrl(string url) + public Playlist? GetPlaylistByName(string name) { foreach (Playlist p in StubPlaylist.Playlists) { - if (p.ImageURL == url) + if (p.Name == name) { return p; } @@ -267,9 +288,9 @@ public class StubManager : IDataManager title.Genre = genre; } - public void UpdateInfoTitleByName(string url, string name, string newUrl, string info, Artist artist, string description, Genre genre) + public void UpdateInfoTitleByName(string name, string newUrl, string info, Artist artist, string description, Genre genre) { - InfoTitle? title = GetInfoTitleByUrl(url); + InfoTitle? title = GetInfoTitleByName(name); if (title != null) { title.Name = name; @@ -295,9 +316,9 @@ public class StubManager : IDataManager title.Genre = genre; } - public void UpdateInfoTitleByNameByArtistName(string url, string name, string newUrl, string info, string artist, string description, Genre genre) + public void UpdateInfoTitleByNameByArtistName(string name, string newUrl, string info, string artist, string description, Genre genre) { - InfoTitle? title = GetInfoTitleByUrl(url); + InfoTitle? title = GetInfoTitleByName(name); if (title != null) { title.Name = name; @@ -322,9 +343,9 @@ public class StubManager : IDataManager album.Information = info; } - public void UpdateAlbumByUrl(string url, string name, string newUrl, Artist artist, string description, string info) + public void UpdateAlbumByName(string name, string newUrl, Artist artist, string description, string info) { - Album? album = GetAlbumByUrl(url); + Album? album = GetAlbumByName(name); if (album != null) { album.Name = name; @@ -348,9 +369,9 @@ public class StubManager : IDataManager album.Information = info; } - public void UpdateAlbumByUrlByArtistName(string url, string name, string newUrl, string artist, string description, string info) + public void UpdateAlbumByNameByArtistName(string name, string newUrl, string artist, string description, string info) { - Album? album = GetAlbumByUrl(url); + Album? album = GetAlbumByName(name); if (album != null) { album.Name = name; @@ -372,9 +393,9 @@ public class StubManager : IDataManager playlist.ImageURL = url; } - public void UpdatePlaylistByUrl(string url, string name, string description, string newUrl) + public void UpdatePlaylistByName(string name, string description, string newUrl) { - Playlist? playlist = GetPlaylistByUrl(url); + Playlist? playlist = GetPlaylistByName(name); if (playlist != null) { playlist.Name = name; @@ -449,11 +470,11 @@ public class StubManager : IDataManager return false; } - public bool ExistsPlaylistByUrl(string url) + public bool ExistsPlaylistByName(string name) { foreach (Playlist p in StubPlaylist.Playlists) { - if (p.ImageURL == url) + if (p.Name == name) { return true; } @@ -473,11 +494,11 @@ public class StubManager : IDataManager return false; } - public bool ExistsAlbumByUrl(string url) + public bool ExistsAlbumByName(string name) { foreach (Album a in StubAlbum.Albums) { - if (a.ImageURL == url) + if (a.Name == name) { return true; } @@ -545,11 +566,11 @@ public class StubManager : IDataManager return false; } - public bool ExistsInfoTitleByUrl(string url) + public bool ExistsInfoTitleByName(string name) { foreach (InfoTitle it in StubInfoTitle.InfoTitles) { - if (it.ImageURL == url) + if (it.Name == name) { return true; }