Started the Split
Split Json data models coming from REST Api, from the Database models storing them in a SQLite database. Work to re-engineer endpoints to use Database objects, and copy/update data from the json objects. More work is needed.
This commit is contained in:
parent
157d46ee2e
commit
4985dc4179
36 changed files with 684 additions and 323 deletions
23
FreeTubeSync/Model/Database/History.cs
Normal file
23
FreeTubeSync/Model/Database/History.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class History
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string author { get; set; } = string.Empty;
|
||||
public string authorId { get; set; } = string.Empty;
|
||||
public long published { get; set; }
|
||||
public string description { get; set; } = string.Empty;
|
||||
public long viewCount { get; set; }
|
||||
public long lengthSeconds { get; set; }
|
||||
public float watchProgress { get; set; }
|
||||
public long timeWatched { get; set; }
|
||||
public bool isLive { get; set; }
|
||||
public string type { get; set; } = string.Empty;
|
||||
public string lastViewedPlaylistType { get; set; } = string.Empty;
|
||||
public string? lastViewedPlaylistItemId { get; set; }
|
||||
}
|
||||
14
FreeTubeSync/Model/Database/Playlist.cs
Normal file
14
FreeTubeSync/Model/Database/Playlist.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class Playlist
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string playlistName { get; set; } = string.Empty;
|
||||
public bool @protected { get; set; }
|
||||
public List<Video> videos { get; set; } = [];
|
||||
public long createdAt { get; set; }
|
||||
public long lastUpdatedAt { get; set; }
|
||||
}
|
||||
13
FreeTubeSync/Model/Database/Profile.cs
Normal file
13
FreeTubeSync/Model/Database/Profile.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class Profile
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string name { get; set; } = string.Empty;
|
||||
public string bgColor { get; set; } = string.Empty;
|
||||
public string textColor { get; set; } = string.Empty;
|
||||
public List<Subscription> subscriptions { get; set; } = [];
|
||||
}
|
||||
10
FreeTubeSync/Model/Database/SearchHistory.cs
Normal file
10
FreeTubeSync/Model/Database/SearchHistory.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class SearchHistory
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public long lastUpdatedAt { get; set; }
|
||||
}
|
||||
10
FreeTubeSync/Model/Database/Setting.cs
Normal file
10
FreeTubeSync/Model/Database/Setting.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class Setting
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; }
|
||||
public string value { get; set; }
|
||||
}
|
||||
11
FreeTubeSync/Model/Database/Subscription.cs
Normal file
11
FreeTubeSync/Model/Database/Subscription.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class Subscription
|
||||
{
|
||||
[Key]
|
||||
public string id { get; set; } = string.Empty;
|
||||
public string name { get; set; } = string.Empty;
|
||||
public string? thumbnail { get; set; }
|
||||
}
|
||||
17
FreeTubeSync/Model/Database/Video.cs
Normal file
17
FreeTubeSync/Model/Database/Video.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FreeTubeSync.Model.Database;
|
||||
|
||||
public class Video
|
||||
{
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string author { get; set; } = string.Empty;
|
||||
public string authorId { get; set; } = string.Empty;
|
||||
public string lengthSeconds { get; set; } = string.Empty;
|
||||
public long pubished { get; set; }
|
||||
public long timeAdded { get; set; }
|
||||
[Key]
|
||||
public string playlistItemId { get; set; } = string.Empty;
|
||||
public string type { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class History
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string author { get; set; } = string.Empty;
|
||||
public string authorId { get; set; } = string.Empty;
|
||||
public long published { get; set; }
|
||||
public string description { get; set; } = string.Empty;
|
||||
public long viewCount { get; set; }
|
||||
public long lengthSeconds { get; set; }
|
||||
public float watchProgress { get; set; }
|
||||
public long timeWatched { get; set; }
|
||||
public bool isLive { get; set; }
|
||||
public string type { get; set; } = string.Empty;
|
||||
public string lastViewedPlaylistType { get; set; } = string.Empty;
|
||||
public string? lastViewedPlaylistItemId { get; set; }
|
||||
|
||||
public void Update(History other)
|
||||
{
|
||||
if (other.videoId != videoId) videoId = other.videoId;
|
||||
if (other.title != title) title = other.title;
|
||||
if (other.author != author) author = other.author;
|
||||
if (other.authorId != authorId) authorId = other.authorId;
|
||||
if (other.published != published) published = other.published;
|
||||
if (other.description != description) description = other.description;
|
||||
if (other.viewCount != viewCount) viewCount = other.viewCount;
|
||||
if (other.lengthSeconds != lengthSeconds) lengthSeconds = other.lengthSeconds;
|
||||
if (!other.watchProgress.Equals(watchProgress)) watchProgress = other.watchProgress;
|
||||
if (other.timeWatched != timeWatched) timeWatched = other.timeWatched;
|
||||
if (other.isLive != isLive) isLive = other.isLive;
|
||||
if (other.type != type) type = other.type;
|
||||
if (other.lastViewedPlaylistType != lastViewedPlaylistType) lastViewedPlaylistType = other.lastViewedPlaylistType;
|
||||
if (other.lastViewedPlaylistItemId != lastViewedPlaylistItemId) lastViewedPlaylistItemId = other.lastViewedPlaylistItemId;
|
||||
}
|
||||
}
|
||||
23
FreeTubeSync/Model/Json/HistoryJson.cs
Normal file
23
FreeTubeSync/Model/Json/HistoryJson.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class HistoryJson
|
||||
{
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string author { get; set; } = string.Empty;
|
||||
public string authorId { get; set; } = string.Empty;
|
||||
public long published { get; set; }
|
||||
public string description { get; set; } = string.Empty;
|
||||
public long viewCount { get; set; }
|
||||
public long lengthSeconds { get; set; }
|
||||
public float watchProgress { get; set; }
|
||||
public long timeWatched { get; set; }
|
||||
public bool isLive { get; set; }
|
||||
public string type { get; set; } = string.Empty;
|
||||
public string lastViewedPlaylistType { get; set; } = string.Empty;
|
||||
public string? lastViewedPlaylistItemId { get; set; }
|
||||
}
|
||||
14
FreeTubeSync/Model/Json/PlaylistJson.cs
Normal file
14
FreeTubeSync/Model/Json/PlaylistJson.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class PlaylistJson
|
||||
{
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string playlistName { get; set; } = string.Empty;
|
||||
public bool @protected { get; set; }
|
||||
public List<VideoJson> videos { get; set; } = [];
|
||||
public long createdAt { get; set; }
|
||||
public long lastUpdatedAt { get; set; }
|
||||
}
|
||||
13
FreeTubeSync/Model/Json/ProfileJson.cs
Normal file
13
FreeTubeSync/Model/Json/ProfileJson.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class ProfileJson
|
||||
{
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string name { get; set; } = string.Empty;
|
||||
public string bgColor { get; set; } = string.Empty;
|
||||
public string textColor { get; set; } = string.Empty;
|
||||
public List<SubscriptionJson> subscriptions { get; set; } = [];
|
||||
}
|
||||
10
FreeTubeSync/Model/Json/SearchHistoryJson.cs
Normal file
10
FreeTubeSync/Model/Json/SearchHistoryJson.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class SearchHistoryJson
|
||||
{
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public long lastUpdatedAt { get; set; }
|
||||
}
|
||||
10
FreeTubeSync/Model/Json/SettingJson.cs
Normal file
10
FreeTubeSync/Model/Json/SettingJson.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class SettingJson
|
||||
{
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public object value { get; set; }
|
||||
}
|
||||
11
FreeTubeSync/Model/Json/SubscriptionJson.cs
Normal file
11
FreeTubeSync/Model/Json/SubscriptionJson.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class SubscriptionJson
|
||||
{
|
||||
public string id { get; set; } = string.Empty;
|
||||
public string name { get; set; } = string.Empty;
|
||||
public string? thumbnail { get; set; }
|
||||
}
|
||||
18
FreeTubeSync/Model/Json/VideoJson.cs
Normal file
18
FreeTubeSync/Model/Json/VideoJson.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model.Json;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class VideoJson
|
||||
{
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string author { get; set; } = string.Empty;
|
||||
public string authorId { get; set; } = string.Empty;
|
||||
public string lengthSeconds { get; set; } = string.Empty;
|
||||
public long pubished { get; set; }
|
||||
public long timeAdded { get; set; }
|
||||
public string playlistItemId { get; set; } = string.Empty;
|
||||
public string type { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Playlist
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string playlistName { get; set; } = string.Empty;
|
||||
public bool @protected { get; set; }
|
||||
public List<Video> videos { get; set; } = [];
|
||||
public long createdAt { get; set; }
|
||||
public long lastUpdatedAt { get; set; }
|
||||
|
||||
public void Update(Playlist other)
|
||||
{
|
||||
if (other.playlistName != playlistName) playlistName = other.playlistName;
|
||||
if (other.@protected != @protected) @protected = other.@protected;
|
||||
var remove = new List<Video>();
|
||||
foreach (var vid in videos)
|
||||
{
|
||||
if (other.videos.Any(x => x.playlistItemId == vid.playlistItemId)) continue;
|
||||
remove.Add(vid);
|
||||
}
|
||||
videos.RemoveAll(x => remove.Contains(x));
|
||||
remove.Clear();
|
||||
foreach (var vid in other.videos)
|
||||
{
|
||||
if (videos.Any(x => x.playlistItemId == vid.playlistItemId)) continue;
|
||||
remove.Add(vid);
|
||||
}
|
||||
videos.AddRange(remove);
|
||||
if (other.createdAt != createdAt) createdAt = other.createdAt;
|
||||
if (other.lastUpdatedAt != lastUpdatedAt) lastUpdatedAt = other.lastUpdatedAt;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Profile
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string name { get; set; } = string.Empty;
|
||||
public string bgColor { get; set; } = string.Empty;
|
||||
public string textColor { get; set; } = string.Empty;
|
||||
public List<Subscription> subscriptions { get; set; } = [];
|
||||
|
||||
public void Update(Profile other)
|
||||
{
|
||||
if (other.name != name) name = other.name;
|
||||
if (other.bgColor != bgColor) bgColor = other.bgColor;
|
||||
if (other.textColor != textColor) textColor = other.textColor;
|
||||
var remove = new List<Subscription>();
|
||||
foreach (var sub in subscriptions)
|
||||
{
|
||||
if (other.subscriptions.Any(x => x.id == sub.id)) continue;
|
||||
remove.Add(sub);
|
||||
}
|
||||
subscriptions.RemoveAll(x => remove.Contains(x));
|
||||
remove.Clear();
|
||||
foreach (var sub in other.subscriptions)
|
||||
{
|
||||
if (subscriptions.Any(x => x.id == sub.id)) continue;
|
||||
remove.Add(sub);
|
||||
}
|
||||
subscriptions.AddRange(remove);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class SearchHistory
|
||||
{
|
||||
[Key]
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public long lastUpdatedAt { get; set; }
|
||||
|
||||
public void Update(SearchHistory other)
|
||||
{
|
||||
if (other.lastUpdatedAt != lastUpdatedAt) lastUpdatedAt = other.lastUpdatedAt;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Setting
|
||||
{
|
||||
[Key]
|
||||
#pragma warning disable CS8618
|
||||
public string _id { get; set; } = string.Empty;
|
||||
public string? ValueJson { get; set; }
|
||||
#pragma warning restore CS8618
|
||||
|
||||
[NotMapped]
|
||||
public object Value
|
||||
{
|
||||
#pragma warning disable CS8603
|
||||
get => string.IsNullOrEmpty(ValueJson) ? null : JsonSerializer.Deserialize<object>(ValueJson);
|
||||
#pragma warning restore CS8603
|
||||
set => ValueJson = JsonSerializer.Serialize(value);
|
||||
}
|
||||
|
||||
public void Update(Setting other)
|
||||
{
|
||||
Value = other.Value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Subscription
|
||||
{
|
||||
[Key]
|
||||
public required string id { get; set; }
|
||||
public required string name { get; set; }
|
||||
public string? thumbnail { get; set; }
|
||||
|
||||
public void Update(Subscription other)
|
||||
{
|
||||
name = other.name;
|
||||
thumbnail = other.thumbnail;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FreeTubeSync.Model;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class Video
|
||||
{
|
||||
public string videoId { get; set; } = string.Empty;
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string author { get; set; } = string.Empty;
|
||||
public string authorId { get; set; } = string.Empty;
|
||||
public string lengthSeconds { get; set; } = string.Empty;
|
||||
public long pubished { get; set; }
|
||||
public long timeAdded { get; set; }
|
||||
[Key] public string playlistItemId { get; set; } = string.Empty;
|
||||
public string type { get; set; } = string.Empty;
|
||||
|
||||
public void Update(Video other)
|
||||
{
|
||||
videoId = other.videoId;
|
||||
title = other.title;
|
||||
author = other.author;
|
||||
authorId = other.authorId;
|
||||
lengthSeconds = other.lengthSeconds;
|
||||
pubished = other.pubished;
|
||||
timeAdded = other.timeAdded;
|
||||
type = other.type;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue