forked from sanchezvem/PyroFetes
Ajout de Login et du model réuni avec tout les autres Sujet
This commit is contained in:
35
PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs
Normal file
35
PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using PyroFetes.DTO.Login.Request;
|
||||
using PyroFetes.DTO.Login.Response;
|
||||
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("/api/logins/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct)
|
||||
{
|
||||
var login = await database.Logins.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (login == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Logins.Remove(login);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user