diff --git a/FreeTubeSyncer/Models/DatabaseModels/History.cs b/FreeTubeSyncer/Models/DatabaseModels/History.cs index 7630133..abc37cf 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/History.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/History.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics.CodeAnalysis; using System.Text.Json; using FreeTubeSyncer.Library; @@ -5,7 +6,7 @@ using FreeTubeSyncer.Library; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class History : IDataModel +public class History : IDataModel, IEquatable { public string _id { get; set; } = string.Empty; public string videoId { get; set; } = string.Empty; @@ -52,4 +53,45 @@ public class History : IDataModel { return JsonSerializer.Serialize(this); } + + public bool Equals(History? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return _id == other._id && videoId == other.videoId && title == other.title && author == other.author && + authorId == other.authorId && published == other.published && description == other.description && + viewCount == other.viewCount && lengthSeconds == other.lengthSeconds && + watchProgress.Equals(other.watchProgress) && timeWatched == other.timeWatched && + isLive == other.isLive && type == other.type && lastViewedPlaylistType == other.lastViewedPlaylistType && + lastViewedPlaylistItemId == other.lastViewedPlaylistItemId; + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((History)obj); + } + + public override int GetHashCode() + { + var hashCode = new HashCode(); + hashCode.Add(_id); + hashCode.Add(videoId); + hashCode.Add(title); + hashCode.Add(author); + hashCode.Add(authorId); + hashCode.Add(published); + hashCode.Add(description); + hashCode.Add(viewCount); + hashCode.Add(lengthSeconds); + hashCode.Add(watchProgress); + hashCode.Add(timeWatched); + hashCode.Add(isLive); + hashCode.Add(type); + hashCode.Add(lastViewedPlaylistType); + hashCode.Add(lastViewedPlaylistItemId); + return hashCode.ToHashCode(); + } } \ No newline at end of file diff --git a/FreeTubeSyncer/Models/DatabaseModels/Playlist.cs b/FreeTubeSyncer/Models/DatabaseModels/Playlist.cs index ff04601..79bd4f6 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/Playlist.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/Playlist.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text.Json; @@ -6,7 +7,7 @@ using FreeTubeSyncer.Library; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class Playlist : IDataModel +public class Playlist : IDataModel, IEquatable { public string _id { get; set; } = string.Empty; public string playlistName { get; set; } = string.Empty; @@ -34,4 +35,25 @@ public class Playlist : IDataModel { return JsonSerializer.Serialize(this); } + + public bool Equals(Playlist? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return _id == other._id && playlistName == other.playlistName && @protected == other.@protected && + videos.Equals(other.videos) && createdAt == other.createdAt && lastUpdatedAt == other.lastUpdatedAt; + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Playlist)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(_id, playlistName, @protected, videos, createdAt, lastUpdatedAt); + } } \ No newline at end of file diff --git a/FreeTubeSyncer/Models/DatabaseModels/Profile.cs b/FreeTubeSyncer/Models/DatabaseModels/Profile.cs index c97530e..fd795f0 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/Profile.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/Profile.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text.Json; @@ -6,7 +7,7 @@ using FreeTubeSyncer.Library; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class Profile : IDataModel +public class Profile : IDataModel, IEquatable { public string _id { get; set; } = string.Empty; public string name { get; set; } = string.Empty; @@ -32,4 +33,25 @@ public class Profile : IDataModel { return JsonSerializer.Serialize(this); } + + public bool Equals(Profile? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return _id == other._id && name == other.name && bgColor == other.bgColor && textColor == other.textColor && + subscriptions.Equals(other.subscriptions); + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Profile)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(_id, name, bgColor, textColor, subscriptions); + } } \ No newline at end of file diff --git a/FreeTubeSyncer/Models/DatabaseModels/SearchHistory.cs b/FreeTubeSyncer/Models/DatabaseModels/SearchHistory.cs index 93ddada..4237826 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/SearchHistory.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/SearchHistory.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics.CodeAnalysis; using System.Text.Json; using FreeTubeSyncer.Library; @@ -5,7 +6,7 @@ using FreeTubeSyncer.Library; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class SearchHistory : IDataModel +public class SearchHistory : IDataModel, IEquatable { public string _id { get; set; } = string.Empty; public long lastUpdatedAt { get; set; } @@ -25,4 +26,24 @@ public class SearchHistory : IDataModel { return JsonSerializer.Serialize(this); } + + public bool Equals(SearchHistory? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return _id == other._id && lastUpdatedAt == other.lastUpdatedAt; + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((SearchHistory)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(_id, lastUpdatedAt); + } } \ No newline at end of file diff --git a/FreeTubeSyncer/Models/DatabaseModels/Setting.cs b/FreeTubeSyncer/Models/DatabaseModels/Setting.cs index 42af9ca..4d656bb 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/Setting.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/Setting.cs @@ -1,10 +1,11 @@ +using System; using System.Diagnostics.CodeAnalysis; using System.Text.Json; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class Setting : IDataModel +public class Setting : IDataModel, IEquatable { #pragma warning disable CS8618 public string _id { get; set; } = string.Empty; @@ -23,4 +24,24 @@ public class Setting : IDataModel { return value; } + + public bool Equals(Setting? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return _id == other._id && value == other.value; + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Setting)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(_id, value); + } } \ No newline at end of file diff --git a/FreeTubeSyncer/Models/DatabaseModels/Subscription.cs b/FreeTubeSyncer/Models/DatabaseModels/Subscription.cs index faf3315..891e881 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/Subscription.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/Subscription.cs @@ -1,11 +1,32 @@ +using System; using System.Diagnostics.CodeAnalysis; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class Subscription +public class Subscription : IEquatable { public required string id { get; set; } public required string name { get; set; } public string? thumbnail { get; set; } + + public bool Equals(Subscription? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return id == other.id && name == other.name && thumbnail == other.thumbnail; + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Subscription)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(id, name, thumbnail); + } } \ No newline at end of file diff --git a/FreeTubeSyncer/Models/DatabaseModels/Video.cs b/FreeTubeSyncer/Models/DatabaseModels/Video.cs index 2cde410..d39cf7c 100644 --- a/FreeTubeSyncer/Models/DatabaseModels/Video.cs +++ b/FreeTubeSyncer/Models/DatabaseModels/Video.cs @@ -1,9 +1,10 @@ +using System; using System.Diagnostics.CodeAnalysis; namespace FreeTubeSyncer.Models.DatabaseModels; [SuppressMessage("ReSharper", "InconsistentNaming")] -public class Video +public class Video : IEquatable