2025-07-19 04:02:09 -05:00
|
|
|
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<Profile> repository, CancellationToken ct) =>
|
|
|
|
|
{
|
|
|
|
|
var results = await repository.GetAllAsync(ct);
|
|
|
|
|
return Results.Ok(results);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group.MapPost("/", async (IRepository<Profile> repository, CancellationToken ct, Profile profile) =>
|
|
|
|
|
{
|
|
|
|
|
var res = await repository.GetByIdAsync(profile._id, ct);
|
|
|
|
|
if (res == null)
|
|
|
|
|
await repository.AddAsync(profile, ct);
|
|
|
|
|
else
|
2025-07-21 17:10:42 -05:00
|
|
|
{
|
|
|
|
|
res.Update(profile);
|
|
|
|
|
await repository.UpdateAsync(res, ct);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 04:02:09 -05:00
|
|
|
return Results.Ok();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group.MapDelete("/{id}", async (IRepository<Profile> 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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|