Added all the endpoints needed for Deliverer

This commit is contained in:
Cristiano
2025-11-06 15:54:53 +01:00
parent 3192d399cc
commit 554ba9b725
6 changed files with 181 additions and 0 deletions

View 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);
}
}