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 { public override void Configure() { Put ("/api/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); } }