diff --git a/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs b/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs index 47fa206..dfc7dde 100644 --- a/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs +++ b/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs @@ -5,4 +5,5 @@ public class CreateCommunicationDto public string? Calling { get; set; } public string? Email { get; set; } public string? Meeting { get; set; } + public int ContactId { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs b/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs index ea0432d..9faf06c 100644 --- a/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs +++ b/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs @@ -6,4 +6,11 @@ public class GetCommunicationDto public string? Calling { get; set; } public string? Email { get; set; } public string? Meeting { get; set; } + + public int ContactId { get; set; } + + public string? ContactFirstName { get; set; } + public string? ContactLastName { get; set; } + public string? ContactEmail { get; set; } + public string? ContactPhoneNumber { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs index 052c400..744ab77 100644 --- a/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs +++ b/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs @@ -19,16 +19,22 @@ public class CreateCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) { Calling = req.Calling, Email = req.Email, - Meeting = req.Meeting + Meeting = req.Meeting, + ContactId = req.ContactId }; pyroFetesDbContext.Add(communication); await pyroFetesDbContext.SaveChangesAsync(ct); GetCommunicationDto response = new() { - Calling = req.Calling, - Email = req.Email, - Meeting = req.Meeting + 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); diff --git a/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs b/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs index a9b6d30..c1544fe 100644 --- a/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs +++ b/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs @@ -14,12 +14,17 @@ public class GetAllCommunicationsEndpoint(PyroFetesDbContext pyroFetesDbContext) public override async Task HandleAsync(CancellationToken ct) { - List communications = await pyroFetesDbContext.Communications.Select(x => new GetCommunicationDto() + List communications = await pyroFetesDbContext.Communications.Include(x => x.Contact).Select(x => new GetCommunicationDto() { Id = x.Id, Calling = x.Calling, Email = x.Email, Meeting = x.Meeting, + ContactId = x.ContactId, + ContactFirstName = x.Contact.FirstName, + ContactLastName = x.Contact.LastName, + ContactPhoneNumber = x.Contact.PhoneNumber, + ContactEmail = x.Contact.Email, }).ToListAsync(ct); await Send.OkAsync(communications, ct); diff --git a/PyroFetes/Endpoints/Contact/CreateContactEndpoint.cs b/PyroFetes/Endpoints/Contact/CreateContactEndpoint.cs index 768cb2f..a2dd49b 100644 --- a/PyroFetes/Endpoints/Contact/CreateContactEndpoint.cs +++ b/PyroFetes/Endpoints/Contact/CreateContactEndpoint.cs @@ -48,7 +48,7 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp Address = contact.Address, City = contact.City, Role = contact.Role, - CustomerId = contact.CustomerId, + CustomerId = databaseCustomer.Id, }; await Send.OkAsync(response, ct);