| | | 1 | | using KT.Modules.Alarm.Core.Domain; |
| | | 2 | | using KT.Modules.Alarm.Core.Domain.Ports; |
| | | 3 | | using KT.Modules.Alarm.Presentation.Contracts; |
| | | 4 | | |
| | | 5 | | namespace KT.Modules.Alarm.Core.Application |
| | | 6 | | { |
| | 4 | 7 | | internal class SendRequestService(IRequestRepository requestRepository, IConnectionRepository connectionRepository) |
| | | 8 | | { |
| | | 9 | | public async Task SendAsync(string userSender, string receivingUser) |
| | 4 | 10 | | { |
| | 4 | 11 | | if (receivingUser.Equals(userSender)) |
| | 1 | 12 | | throw new InvalidOperationException("You can't send an application to yourself."); |
| | | 13 | | // Verificar si ya hay una solicitud pendiente entre los dos usuarios |
| | 3 | 14 | | if (await requestRepository.ExistsPendingRequestAsync(userSender, receivingUser)) |
| | 1 | 15 | | throw new InvalidOperationException("There is already a pending request between the two users."); |
| | | 16 | | // verificar si ya hay una conexion entre los dos usuarios |
| | 2 | 17 | | if (await connectionRepository.ExistsConnectionAsync(userSender, receivingUser)) |
| | 1 | 18 | | throw new InvalidOperationException("There is already a connection between the two users."); |
| | | 19 | | |
| | | 20 | | // Guardar la solicitud |
| | 1 | 21 | | var userRequest = new UserRequest(userSender, receivingUser); |
| | 1 | 22 | | await requestRepository.SaveRequestAsync(userRequest); |
| | 1 | 23 | | } |
| | | 24 | | } |
| | | 25 | | } |