42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.Communication.Request;
|
|
using PyroFetes.DTO.Communication.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Communication;
|
|
|
|
public class CreateCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateCommunicationDto, GetCommunicationDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/communications");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
|
|
public override async Task HandleAsync(CreateCommunicationDto req, CancellationToken ct)
|
|
{
|
|
Models.Communication communication = new()
|
|
{
|
|
Calling = req.Calling,
|
|
Email = req.Email,
|
|
Meeting = req.Meeting,
|
|
ContactId = req.ContactId
|
|
};
|
|
pyroFetesDbContext.Add(communication);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
GetCommunicationDto response = new()
|
|
{
|
|
Calling = communication.Calling,
|
|
Email = communication.Email,
|
|
Meeting = communication.Meeting,
|
|
ContactId = communication.ContactId,
|
|
ContactFirstName = communication.Contact?.FirstName,
|
|
ContactLastName = communication.Contact?.LastName,
|
|
ContactEmail = communication.Contact?.Email,
|
|
ContactPhoneNumber = communication.Contact?.PhoneNumber,
|
|
};
|
|
|
|
await Send.OkAsync(response, ct);
|
|
}
|
|
} |