2025-07-19 04:02:09 -05:00
|
|
|
using FreeTubeSync.Model;
|
|
|
|
|
|
|
|
|
|
namespace FreeTubeSync.EndPoints;
|
|
|
|
|
|
|
|
|
|
public static class SearchHistoryEndpoint
|
|
|
|
|
{
|
|
|
|
|
public static void MapSearchHistoryEndpoints(this WebApplication app)
|
|
|
|
|
{
|
|
|
|
|
var group = app.MapGroup("searchHistory");
|
|
|
|
|
|
2025-07-19 12:40:00 -05:00
|
|
|
group.MapGet("/", async (IRepository<SearchHistory> repository, CancellationToken ct) =>
|
2025-07-19 04:02:09 -05:00
|
|
|
{
|
|
|
|
|
var result = await repository.GetAllAsync(ct);
|
|
|
|
|
return Results.Ok(result);
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-19 12:40:00 -05:00
|
|
|
group.MapPost("/", async (IRepository<SearchHistory> repository, CancellationToken ct, SearchHistory history) =>
|
2025-07-19 04:02:09 -05:00
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-19 12:40:00 -05:00
|
|
|
group.MapDelete("/{id}", async (IRepository<SearchHistory> repository, CancellationToken ct, string id) =>
|
2025-07-19 04:02:09 -05:00
|
|
|
{
|
|
|
|
|
var result = await repository.GetByIdAsync(id, ct);
|
|
|
|
|
if (result == null) return Results.NotFound();
|
|
|
|
|
await repository.DeleteAsync(result, ct);
|
|
|
|
|
return Results.Ok();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|