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:
Mario Steele 2025-07-22 17:03:33 -05:00
parent 157d46ee2e
commit 4985dc4179
36 changed files with 684 additions and 323 deletions

View file

@ -1,4 +1,4 @@
using FreeTubeSync.Model;
using FreeTubeSync.Model.Database;
using Microsoft.EntityFrameworkCore;
namespace FreeTubeSync.Database;
@ -12,25 +12,8 @@ public class DataContext : DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Setting>()
.ToTable("Settings")
.HasKey(s => s._id);
modelBuilder.Entity<Setting>()
.Property(s => s.ValueJson)
.HasColumnName("Value")
.IsRequired();
modelBuilder.Entity<Profile>()
.ToTable("Profiles")
.HasKey(s => s._id);
modelBuilder.Entity<Profile>()
.Navigation(e => e.subscriptions).AutoInclude();
modelBuilder.Entity<Playlist>()
.ToTable("Playlists")
.HasKey(s => s._id);
modelBuilder.Entity<Playlist>()
.Navigation(e => e.videos).AutoInclude();

View file

@ -0,0 +1,36 @@
using System.Collections;
namespace FreeTubeSync.Database;
public static class MapData
{
public static void MapFrom(this object obj1, object obj2)
{
var props = new Dictionary<string, object?>();
var t1Type = obj1.GetType();
var t2Type = obj2.GetType();
var properties = t1Type.GetProperties();
foreach (var property in properties)
{
props[property.Name] = property.GetValue(obj1);
}
properties = t2Type.GetProperties();
foreach (var property in properties)
{
if (props[property.Name] is not IEnumerable)
property.SetValue(obj2, props[property.Name]);
}
}
public static void MapTo<T1, T2>(this IEnumerable<T1> obj1, IList<T2> obj2)
where T1 : class where T2 : class, new()
{
foreach (var obj in obj1)
{
var newObj = new T2();
newObj.MapFrom(obj);
obj2.Add(newObj);
}
}
}