Files
Projet4/PyroFetes/Endpoints/Contact/GetAllContactsEndpoint.cs
carteronm 4e64112a31 First Commit 09/10
# Conflicts:
#	PyroFetes/PyroFetes.csproj
2025-10-16 17:34:55 +02:00

30 lines
861 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Contact.Response;
namespace PyroFetes.Endpoints.Contact;
public class GetAllContactxuest(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetContactDto>>
{
public override void Configure()
{
Get ("/api/contacts");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetContactDto> contacts = await pyroFetesDbContext.Contacts.Select(x => new GetContactDto()
{
Id = x.Id,
LastName = x.LastName,
FirstName = x.FirstName,
PhoneNumber = x.PhoneNumber,
Email = x.Email,
Address = x.Address,
Role = x.Role,
}).ToListAsync(ct);
await Send.OkAsync(contacts, ct);
}
}