add missed dto/enbdpoints
This commit is contained in:
30
PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Customer.Request;
|
||||
using PyroFetes.DTO.Customer.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Customer;
|
||||
|
||||
public class DeleteCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerRequest, GetCustomerDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete ("/api/Customer/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct)
|
||||
{
|
||||
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseCustomer == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
pyroFetesDbContext.Customers.Remove(databaseCustomer);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user