Files
Projet4/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs
T
2026-06-09 13:29:58 +02:00

33 lines
1.1 KiB
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Communication.Response;
namespace PyroFetes.Endpoints.Communication;
public class GetAllCommunicationsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCommunicationDto>>
{
public override void Configure()
{
Get ("/communications");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetCommunicationDto> communications = await pyroFetesDbContext.Communications.Include(x => x.Contact).Select(x => new GetCommunicationDto()
{
Id = x.Id,
Calling = x.Calling,
Email = x.Email,
Meeting = x.Meeting,
ContactId = x.ContactId,
ContactFirstName = x.Contact.FirstName,
ContactLastName = x.Contact.LastName,
ContactPhoneNumber = x.Contact.PhoneNumber,
ContactEmail = x.Contact.Email,
}).ToListAsync(ct);
await Send.OkAsync(communications, ct);
}
}