< Summary

Information
Class: KT.Modules.Security.Core.Application.SearchUserService
Assembly: KT.Modules.Security
File(s): G:\NetProjects\KeepTrack\src\Modules\KT.Modules.Security\Core\Application\SearchUserService.cs
Line coverage
100%
Covered lines: 44
Uncovered lines: 0
Coverable lines: 44
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetProfile()100%44100%
SearchAsync()100%44100%
SearchByIdAsync()100%44100%

File(s)

G:\NetProjects\KeepTrack\src\Modules\KT.Modules.Security\Core\Application\SearchUserService.cs

#LineLine coverage
 1using KT.Domain.Ports;
 2using KT.Modules.Security.Presentation.Contracts;
 3using KT.Modules.Security.Presentation.Dto;
 4
 5namespace KT.Modules.Security.Core.Application
 6{
 117    internal class SearchUserService(IUserRepository userRepository, IConnectionProvider connectionProvider) : ISearchUs
 8    {
 9        public async Task<ProfileDto> GetProfile(string userId)
 410        {
 411            if (string.IsNullOrEmpty(userId))
 212                throw new ArgumentException("Username cannot be null or empty", nameof(userId));
 213            var userFound = await userRepository.GetAsyncById(userId);
 214            if (userFound == null)
 115                throw new InvalidOperationException("User not found");
 116            var profileDto = new ProfileDto
 117            {
 118                CreatedAt = userFound.CreatedAt,
 119                Email = userFound.Email,
 120                Id = userFound.Id,
 121                RealName = userFound.RealName,
 122                Username = userFound.UsernameDisplay
 123            };
 124            return profileDto;
 125        }
 26
 27        // Agregamos currentUserId como parámetro para saber quién está buscando
 28        public async Task<List<UserDto>> SearchAsync(string username, string currentUserId)
 329        {
 330            if (string.IsNullOrWhiteSpace(username))
 131                return new List<UserDto>();
 32
 33            // PASO 1: Obtener los IDs de los amigos actuales
 34            // (Asumo que tienes un repositorio o método para obtener esto)
 35            // Debería devolver algo como: ["id_de_julitop", "id_de_otro_amigo"]
 236            var friendIds = await connectionProvider.GetFriendIdsAsync(currentUserId);
 37
 38            // Si friendIds es null, inicialízalo para evitar errores
 339            if (friendIds == null) friendIds = new List<string>();
 40
 41            // PASO 2: Agregar TU propio ID a la lista de exclusión
 42            // (Para que no te encuentres a ti mismo en el buscador)
 243            friendIds.Add(currentUserId);
 44
 45            // PASO 3: Buscar en el repositorio pasando la "lista negra"
 246            var usersFound = await userRepository.SearchUsersAsync(username.Trim(), friendIds);
 47
 48            // PASO 4: Mapear a DTO
 349            var userDto = usersFound.Select(u => new UserDto
 350            {
 351                Id = u.Id,
 352                Username = u.UsernameDisplay
 353            }).ToList();
 54
 255            return userDto;
 356        }
 57
 58        public async Task<UserDto> SearchByIdAsync(string userId)
 459        {
 460            if (string.IsNullOrEmpty(userId))
 261                throw new ArgumentException("Username cannot be null or empty", nameof(userId));
 262            var userFound = await userRepository.GetAsyncById(userId);
 263            if (userFound == null)
 164                throw new InvalidOperationException("User not found");
 165            var userDto = new UserDto
 166            {
 167                Id = userFound.Id,
 168                Username = userFound.UsernameDisplay
 169            };
 170            return userDto;
 171        }
 72    }
 73}