freetubesync/FreeTubeSync/EndPoints/SearchHistoryEndpoint.cs

40 lines
1.3 KiB
C#
Raw Normal View History

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