Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs
T
2026-05-24 17:22:03 +01:00

34 lines
928 B
C#

using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class DeleteQuotationRequest
{
public int Id { get; set; }
}
public class DeleteQuotationEndpoint(QuotationsRepository quotationsRepository) : Endpoint<DeleteQuotationRequest>
{
public override void Configure()
{
Delete("/quotations/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
{
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation is null)
{
await Send.NotFoundAsync(ct);
return;
}
await quotationsRepository.DeleteAsync(quotation, ct);
await Send.NoContentAsync(ct);
}
}