forked from sanchezvem/PyroFetes
34 lines
836 B
C#
34 lines
836 B
C#
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);
|
|
}
|
|
} |