Class ProfileService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Service for managing user profiles, including profile retrieval, updates, and photo management. Handles the complete profile lifecycle including education, experience, skills, and builder tags.
public class ProfileService : IProfileService
- Inheritance
-
ProfileService
- Implements
- Inherited Members
Remarks
This service implements the business logic for user profile operations, including:
- Profile retrieval with environment-aware photo URL mapping
- Profile updates with validation and data transformation
- Management of related entities (education, experience, skills, tags)
- Profile photo handling with support for S3 keys and external URLs
Constructors
ProfileService(IUserRepository, ISkillRepository, IUnitOfWork, IS3Service, IHostEnvironment, ILogger<ProfileService>)
Initializes a new instance of the ProfileService class.
public ProfileService(IUserRepository userRepository, ISkillRepository skillRepository, IUnitOfWork unitOfWork, IS3Service s3Service, IHostEnvironment environment, ILogger<ProfileService> logger)
Parameters
userRepositoryIUserRepositoryRepository for user data access
skillRepositoryISkillRepositoryRepository for skill data access
unitOfWorkIUnitOfWorkUnit of work for transaction management
s3ServiceIS3ServiceService for S3 operations (profile photo management)
environmentIHostEnvironmentHosting environment for environment-aware behavior
loggerILogger<ProfileService>Logger for recording operations and errors
Methods
GetProfileAsync(Guid, CancellationToken)
Retrieves the complete profile for a specified user.
public Task<ProfileDto> GetProfileAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user
cancellationTokenCancellationTokenCancellation token to cancel the operation
Returns
- Task<ProfileDto>
A ProfileDto containing the user's profile information
Remarks
This method retrieves the user's profile including:
- Basic profile information (name, summary, location, contact)
- Profile photo URL (mapped using ProfilePhotoMapper for environment-aware behavior)
- Education history
- Work experience
- Skills and builder tags
- Profile completion status
If the user doesn't have a profile yet, returns an empty profile DTO to allow profile completion. Profile photo URLs are mapped using environment-aware logic (presigned URLs in production, object keys in test).
Exceptions
- Exception
Thrown when the user is not found or user email is missing
UpdateProfileAsync(Guid, UpdateProfileRequest, CancellationToken)
Updates an existing user profile or creates a new profile if one doesn't exist.
public Task<ProfileDto> UpdateProfileAsync(Guid userId, UpdateProfileRequest request, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose profile is being updated
requestUpdateProfileRequestThe profile update request containing the new profile data
cancellationTokenCancellationTokenCancellation token to cancel the operation
Returns
- Task<ProfileDto>
A ProfileDto containing the updated profile information
Remarks
This method performs a comprehensive profile update including:
- Basic profile fields (name, summary, location, phone, photo)
- Education entries (adds new, updates existing, removes deleted)
- Experience entries (adds new, updates existing, removes deleted)
- Skills (replaces existing skills with new set if provided)
- Builder tags (replaces existing tags with new set if provided)
- Primary category
Profile photo handling:
- External URLs (e.g., https://example.com/photo.jpg) are stored in ProfilePhotoUrl
- S3 object keys (e.g., profile-photos/user-id/photo.jpg) are stored in both ProfilePhotoS3Key and ProfilePhotoUrl for backward compatibility
- Full S3 URLs are automatically extracted to object keys
Partial updates are supported: if optional collections (skills, tags, educations, experiences) are not provided, existing values are preserved. If provided, they replace the existing collections.
After updating, the profile is marked as complete and the user's UpdatedAt timestamp is updated.
Exceptions
- Exception
Thrown when:
- The user is not found
- Required fields are missing or invalid (FullName, City, Country, Summary with minimum 10 characters)
- One or more specified skills are not found