freetubesync/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs
Mario Steele 0144221712 Initial Commit
Inital Commit of Code base, nothing tested.
2025-07-19 04:02:09 -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<History> repository, CancellationToken ct) =>
{
var result = await repository.GetAllAsync(ct);
return Results.Ok(result);
});
group.MapPost("/", async (IRepository<History> repository, CancellationToken ct, History 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<History> 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();
});
}
}