Update all Models
Made all models implement IEquatable<> generic, allowing for validating of equality of data.
This commit is contained in:
parent
13bb5ac0dd
commit
73a54b91ff
7 changed files with 189 additions and 7 deletions
|
|
@ -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<History>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Playlist>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Profile>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<SearchHistory>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Setting>
|
||||
{
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,32 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSyncer.Models.DatabaseModels;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Subscription
|
||||
public class Subscription : IEquatable<Subscription>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSyncer.Models.DatabaseModels;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Video
|
||||
public class Video : IEquatable<Video>
|
||||
{
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
|
|
@ -14,4 +15,36 @@ public class Video
|
|||
public long timeAdded { get; set; }
|
||||
public string playlistItemId { get; set; } = string.Empty;
|
||||
public string type { get; set; } = string.Empty;
|
||||
|
||||
public bool Equals(Video? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return videoId == other.videoId && title == other.title && author == other.author &&
|
||||
authorId == other.authorId && lengthSeconds == other.lengthSeconds && pubished == other.pubished &&
|
||||
timeAdded == other.timeAdded && playlistItemId == other.playlistItemId && type == other.type;
|
||||
}
|
||||
|
||||
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((Video)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashCode = new HashCode();
|
||||
hashCode.Add(videoId);
|
||||
hashCode.Add(title);
|
||||
hashCode.Add(author);
|
||||
hashCode.Add(authorId);
|
||||
hashCode.Add(lengthSeconds);
|
||||
hashCode.Add(pubished);
|
||||
hashCode.Add(timeAdded);
|
||||
hashCode.Add(playlistItemId);
|
||||
hashCode.Add(type);
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue