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 repository, CancellationToken ct) => { var result = await repository.GetAllAsync(ct); return Results.Ok(result); }); group.MapPost("/", async (IRepository 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 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(); }); } }