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