freetubesync/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs
Mario Steele 2e27078443 Updated SearchHistoryEndpoints.cs
Fixed wrong Model for SearchHistory, was using Regular History class,
instead of SearchHistory class.
2025-07-19 12:40:00 -05:00

36 lines
No EOL
1.2 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.UpdateAsync(history, ct);
else
await repository.AddAsync(history, 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();
});
}
}