From 157d46ee2ecc137e4c176af51fbc145a89683710 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Mon, 21 Jul 2025 17:10:42 -0500 Subject: [PATCH] Updated Endpoints Updated all endpoints to use Update() method of the model, instead of trying to use the data from the REST object directly to update the database. WHen doing so, tracking gets busted in EFCore, so instead, will go through and update all properties of a model from the database object, with the data from the REST object. --- FreeTubeSync/EndPoints/HistoryEndpoint.cs | 5 ++++- FreeTubeSync/EndPoints/PlaylistEndpoint.cs | 6 +++++- FreeTubeSync/EndPoints/ProfileEndpoint.cs | 6 +++++- FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs | 10 +++++++--- FreeTubeSync/EndPoints/SettingEndpoint.cs | 5 ++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/FreeTubeSync/EndPoints/HistoryEndpoint.cs b/FreeTubeSync/EndPoints/HistoryEndpoint.cs index 7f6d0d0..d57c233 100644 --- a/FreeTubeSync/EndPoints/HistoryEndpoint.cs +++ b/FreeTubeSync/EndPoints/HistoryEndpoint.cs @@ -20,7 +20,10 @@ public static class HistoryEndpoint if (results == null) await repository.AddAsync(history, ct); else - await repository.UpdateAsync(history, ct); + { + results.Update(history); + await repository.UpdateAsync(results, ct); + } return Results.Ok(); }); diff --git a/FreeTubeSync/EndPoints/PlaylistEndpoint.cs b/FreeTubeSync/EndPoints/PlaylistEndpoint.cs index a7a962f..383d8da 100644 --- a/FreeTubeSync/EndPoints/PlaylistEndpoint.cs +++ b/FreeTubeSync/EndPoints/PlaylistEndpoint.cs @@ -20,7 +20,11 @@ public static class PlaylistEndpoint if (results == null) await repository.AddAsync(playlist, ct); else - await repository.UpdateAsync(playlist, ct); + { + results.Update(playlist); + await repository.UpdateAsync(results, ct); + } + return Results.Ok(); }); diff --git a/FreeTubeSync/EndPoints/ProfileEndpoint.cs b/FreeTubeSync/EndPoints/ProfileEndpoint.cs index 17b298c..80fc531 100644 --- a/FreeTubeSync/EndPoints/ProfileEndpoint.cs +++ b/FreeTubeSync/EndPoints/ProfileEndpoint.cs @@ -20,7 +20,11 @@ public static class ProfileEndpoint if (res == null) await repository.AddAsync(profile, ct); else - await repository.UpdateAsync(profile, ct); + { + res.Update(profile); + await repository.UpdateAsync(res, ct); + } + return Results.Ok(); }); diff --git a/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs b/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs index 8908ddc..5948186 100644 --- a/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs +++ b/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs @@ -17,10 +17,14 @@ public static class SearchHistoryEndpoint group.MapPost("/", async (IRepository repository, CancellationToken ct, SearchHistory history) => { var result = await repository.GetByIdAsync(history._id, ct); - if (result != null) - await repository.UpdateAsync(history, ct); - else + if (result == null) await repository.AddAsync(history, ct); + else + { + result.Update(history); + await repository.UpdateAsync(result, ct); + } + return Results.Ok(); }); diff --git a/FreeTubeSync/EndPoints/SettingEndpoint.cs b/FreeTubeSync/EndPoints/SettingEndpoint.cs index fdb9dc8..1b053f0 100644 --- a/FreeTubeSync/EndPoints/SettingEndpoint.cs +++ b/FreeTubeSync/EndPoints/SettingEndpoint.cs @@ -22,7 +22,10 @@ public static class SettingEndpoint if (res == null) await repository.AddAsync(setting, ct); else - await repository.UpdateAsync(setting, ct); + { + res.Update(setting); + await repository.UpdateAsync(res, ct); + } return Results.Ok(); });