Files
Projet4/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs
2025-12-04 16:53:00 +01:00

36 lines
1.2 KiB
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Communication.Request;
using PyroFetes.DTO.Communication.Response;
namespace PyroFetes.Endpoints.Communication;
public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationRequest, GetCommunicationDto>
{
public override void Configure()
{
Get ("/communications/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetCommunicationRequest database, CancellationToken ct)
{
Models.Communication? databaseCommunications = await pyroFetesDbContext.Communications.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
if (databaseCommunications == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetCommunicationDto dto = new()
{
Id = databaseCommunications.Id,
Calling = databaseCommunications.Calling,
Email = databaseCommunications.Email,
Meeting = databaseCommunications.Meeting
};
await Send.OkAsync(dto, ct);
}
}