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

43 lines
1.3 KiB
C#

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