Files
Projet4/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs
2025-12-04 15:03:10 +01:00

34 lines
1004 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Customer.Request;
using PyroFetes.DTO.Customer.Response;
namespace PyroFetes.Endpoints.Customer;
public class GetCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerRequest, GetCustomerDto>
{
public override void Configure()
{
Get ("/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;
}
GetCustomerDto dto = new()
{
Id = databaseCustomer.Id,
Note = databaseCustomer.Note,
};
await Send.OkAsync(dto, ct);
}
}