freetubesync/FreeTubeSync/EndPoints/ProfileEndpoint.cs

35 lines
1.2 KiB
C#
Raw Normal View History

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
await repository.UpdateAsync(profile, ct);
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();
});
}
}