| | | 1 | | using KT.Modules.Alarm.Core.Domain.Ports; |
| | | 2 | | using KT.Modules.Alarm.Presentation.Contracts; |
| | | 3 | | using KT.Modules.Alarm.Presentation.Dto; |
| | | 4 | | using KT.Modules.Security.Presentation.Contracts; |
| | | 5 | | |
| | | 6 | | namespace KT.Modules.Alarm.Core.Application |
| | | 7 | | { |
| | 2 | 8 | | internal class AllConnectionsService(IConnectionRepository connectionRepository, ISearchUserService searchUserServic |
| | | 9 | | { |
| | | 10 | | public async Task<List<ConnectionDto>> GetAsync(string userId) |
| | 2 | 11 | | { |
| | | 12 | | try |
| | 2 | 13 | | { |
| | 2 | 14 | | if (string.IsNullOrEmpty(userId)) |
| | 1 | 15 | | throw new ArgumentNullException(nameof(userId)); |
| | 1 | 16 | | var connections = await connectionRepository.GetConnectionUsersAsync(userId); |
| | 1 | 17 | | var connectionDto = new List<ConnectionDto>(); |
| | 5 | 18 | | foreach (var connection in connections) |
| | 1 | 19 | | { |
| | 1 | 20 | | string user = connection.UserId1 == userId ? connection.UserId2 : connection.UserId1; |
| | 1 | 21 | | var userDto = await searchUserService.SearchByIdAsync(user); |
| | 1 | 22 | | connectionDto.Add(new ConnectionDto |
| | 1 | 23 | | { |
| | 1 | 24 | | IdConnection = connection.IdConnection, |
| | 1 | 25 | | UserId = userDto.Id, |
| | 1 | 26 | | ContactName = userDto.Username, |
| | 1 | 27 | | CreatedAt = connection.CreatedAt |
| | 1 | 28 | | }); |
| | 1 | 29 | | } |
| | 1 | 30 | | return connectionDto; |
| | | 31 | | } |
| | 1 | 32 | | catch (Exception ex) |
| | 1 | 33 | | { |
| | 1 | 34 | | throw new Exception("An error occurred while retrieving connections.", ex); |
| | | 35 | | } |
| | 1 | 36 | | } |
| | | 37 | | } |
| | | 38 | | } |