MAJ avec l'authentifiation

This commit is contained in:
2025-12-08 12:27:05 +01:00
parent 78e5a4e960
commit 0a8258017a
13 changed files with 325 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Login;
public class DeleteLoginRequest
{
public int Id { get; set; }
}
public class DeleteLoginEndpoint(PyroFetesDbContext database) : Endpoint<DeleteLoginRequest>
{
public override void Configure()
{
Delete("/logins/{@Id}", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct)
{
Models.User? login = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (login == null)
{
await Send.NotFoundAsync(ct);
return;
}
database.Users.Remove(login);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}