forked from sanchezvem/PyroFetes
Added all the endpoints needed for Deliverer
This commit is contained in:
39
PyroFetes/Endpoints/Deliverers/DeleteDelivererEndpoint.cs
Normal file
39
PyroFetes/Endpoints/Deliverers/DeleteDelivererEndpoint.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Deliverer.Request;
|
||||
using PyroFetes.DTO.Deliverer.Response;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Endpoints.Deliverers;
|
||||
|
||||
public class DeleteDelivererRequest
|
||||
{
|
||||
public int DelivererId { get; set; }
|
||||
}
|
||||
public class DeleteDelivererEndpoint(PyroFetesDbContext database) : Endpoint<DeleteDelivererRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("api/deliverers/{id}", x=>new {x.DelivererId});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteDelivererRequest req, CancellationToken ct)
|
||||
{
|
||||
Deliverer? deliverer = await database.Deliverers.SingleOrDefaultAsync(x=>x.Id == req.DelivererId, ct);
|
||||
|
||||
if (deliverer == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Remove(deliverer);
|
||||
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(ct);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user