freetubesync/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs
Mario Steele 157d46ee2e 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.
2025-07-21 17:10:42 -05:00

40 lines
No EOL
1.3 KiB
C#

using FreeTubeSync.Model;
namespace FreeTubeSync.EndPoints;
public static class SearchHistoryEndpoint
{
public static void MapSearchHistoryEndpoints(this WebApplication app)
{
var group = app.MapGroup("searchHistory");
group.MapGet("/", async (IRepository<SearchHistory> repository, CancellationToken ct) =>
{
var result = await repository.GetAllAsync(ct);
return Results.Ok(result);
});
group.MapPost("/", async (IRepository<SearchHistory> repository, CancellationToken ct, SearchHistory history) =>
{
var result = await repository.GetByIdAsync(history._id, ct);
if (result == null)
await repository.AddAsync(history, ct);
else
{
result.Update(history);
await repository.UpdateAsync(result, ct);
}
return Results.Ok();
});
group.MapDelete("/{id}", async (IRepository<SearchHistory> repository, CancellationToken ct, string id) =>
{
var result = await repository.GetByIdAsync(id, ct);
if (result == null) return Results.NotFound();
await repository.DeleteAsync(result, ct);
return Results.Ok();
});
}
}