Class UserSearchService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Service for searching and retrieving user profiles with role-based access control for sensitive information.
public class UserSearchService : IUserSearchService
- Inheritance
-
UserSearchService
- Implements
- Inherited Members
Remarks
This service provides user search functionality with the following features:
- Search users by text, category, and skills with pagination
- Retrieve individual user profiles
- Role-based data filtering (only admins can see email addresses and phone numbers)
- Environment-aware profile photo URL mapping with presigned URLs
Constructors
UserSearchService(IUserRepository, IS3Service, IHostEnvironment)
Initializes a new instance of the UserSearchService class.
public UserSearchService(IUserRepository userRepository, IS3Service s3Service, IHostEnvironment environment)
Parameters
userRepositoryIUserRepositoryRepository for user data access.
s3ServiceIS3ServiceService for S3 operations (presigned URL generation).
environmentIHostEnvironmentHost environment for determining photo URL mapping strategy.
Methods
GetUserProfileAsync(Guid, string?, CancellationToken)
Retrieves a specific user's profile by ID.
public Task<UserSearchResultDto?> GetUserProfileAsync(Guid userId, string? requestingUserRole = null, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose profile should be retrieved.
requestingUserRolestringOptional role of the requesting user. If "Admin", sensitive information (email, phone) is included in results.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<UserSearchResultDto>
The user profile DTO if found; otherwise, null.
Remarks
Role-based access control:
- Admin role: Can see email addresses and phone numbers
- Other roles: Email and phone numbers are excluded from results
SearchUsersAsync(UserSearchRequest, string?, CancellationToken)
Searches for users matching the specified criteria with pagination support.
public Task<(List<UserSearchResultDto> Users, int TotalCount)> SearchUsersAsync(UserSearchRequest request, string? requestingUserRole = null, CancellationToken cancellationToken = default)
Parameters
requestUserSearchRequestThe search request containing text, category, skills, and pagination parameters.
requestingUserRolestringOptional role of the requesting user. If "Admin", sensitive information (email, phone) is included in results.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<(List<UserSearchResultDto> Users, int TotalCount)>
A tuple containing the list of matching users and the total count of matching users.
Remarks
Search supports:
- Text search (matches user names and profiles)
- Category filtering (e.g., "SoftwareEngineer", "Designer")
- Skills filtering (matches users with specified skills)
- Pagination (page and pageSize)
Role-based access control:
- Admin role: Can see email addresses and phone numbers
- Other roles: Email and phone numbers are excluded from results