36 lines
1.2 KiB
C#
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 ("/api/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);
|
|
}
|
|
} |