freetubesync/FreeTubeSync/EndPoints/HistoryEndpoint.cs

38 lines
1.2 KiB
C#
Raw Normal View History

using FreeTubeSync.Model;
namespace FreeTubeSync.EndPoints;
public static class HistoryEndpoint
{
public static void MapHistoryEndpoints(this WebApplication app)
{
var group = app.MapGroup("history");
group.MapGet("/", async (IRepository<History> repository, CancellationToken ct) =>
{
var results = await repository.GetAllAsync(ct);
return Results.Ok(results);
});
group.MapPost("/", async (IRepository<History> repository, CancellationToken ct, History history) =>
{
var results = await repository.GetByIdAsync(history._id, ct);
if (results == null)
await repository.AddAsync(history, ct);
else
{
results.Update(history);
await repository.UpdateAsync(results, 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();
});
}
}