add missed dto/enbdpoints
This commit is contained in:
38
PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Customer.Request;
|
||||
using PyroFetes.DTO.Customer.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Customer;
|
||||
|
||||
public class UpdateCustomer(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateCustomerDto, GetCustomerDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put ("/api/Customer/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateCustomerDto 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;
|
||||
}
|
||||
else
|
||||
{
|
||||
databaseCustomer.Note = req.Note;
|
||||
}
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetCustomerDto dto = new()
|
||||
{
|
||||
Id = databaseCustomer.Id,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user