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.
This commit is contained in:
Mario Steele 2025-07-21 17:10:42 -05:00
parent 21af6f4300
commit 157d46ee2e
5 changed files with 25 additions and 7 deletions

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -17,10 +17,14 @@ public static class SearchHistoryEndpoint
group.MapPost("/", async (IRepository<SearchHistory> 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();
});

View file

@ -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();
});