Files
Projet4/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs
2025-12-04 15:29:23 +01:00

34 lines
846 B
C#

using FastEndpoints;
using PyroFetes.DTO.Customer.Request;
using PyroFetes.DTO.Customer.Response;
namespace PyroFetes.Endpoints.Customer;
public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateCustomerDto, GetCustomerDto>
{
public override void Configure()
{
Post("/api/customer");
AllowAnonymous();
}
public override async Task HandleAsync(CreateCustomerDto req, CancellationToken ct)
{
var customer = new Models.Customer
{
Note = req.Note
};
pyroFetesDbContext.Add(customer);
await pyroFetesDbContext.SaveChangesAsync(ct);
GetCustomerDto response = new GetCustomerDto()
{
Id = customer.Id,
Note = customer.Note
};
await Send.OkAsync(response, ct);
}
}