Table of Contents

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
Profile photo URLs are automatically converted to presigned URLs (15-minute TTL) for secure access.

Constructors

UserSearchService(IUserRepository, IS3Service, IHostEnvironment)

Initializes a new instance of the UserSearchService class.

public UserSearchService(IUserRepository userRepository, IS3Service s3Service, IHostEnvironment environment)

Parameters

userRepository IUserRepository

Repository for user data access.

s3Service IS3Service

Service for S3 operations (presigned URL generation).

environment IHostEnvironment

Host 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

userId Guid

The unique identifier of the user whose profile should be retrieved.

requestingUserRole string

Optional role of the requesting user. If "Admin", sensitive information (email, phone) is included in results.

cancellationToken CancellationToken

Cancellation 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
Profile photo URLs are automatically converted to presigned URLs for secure access.

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

request UserSearchRequest

The search request containing text, category, skills, and pagination parameters.

requestingUserRole string

Optional role of the requesting user. If "Admin", sensitive information (email, phone) is included in results.

cancellationToken CancellationToken

Cancellation 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
Profile photo URLs are automatically converted to presigned URLs for secure access.