30 lines
793 B
C#

using Customers.Api.Contracts.Requests;
using Customers.Api.Services;
using FastEndpoints;
using Microsoft.AspNetCore.Authorization;
namespace Customers.Api.Endpoints;
[HttpDelete("customers/{id:guid}"), AllowAnonymous]
public class DeleteCustomerEndpoint : Endpoint<DeleteCustomerRequest>
{
private readonly ICustomerService _customerService;
public DeleteCustomerEndpoint(ICustomerService customerService)
{
_customerService = customerService;
}
public override async Task HandleAsync(DeleteCustomerRequest req, CancellationToken ct)
{
var deleted = await _customerService.DeleteAsync(req.Id);
if (!deleted)
{
await SendNotFoundAsync(ct);
return;
}
await SendNoContentAsync(ct);
}
}