Class ProjectService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Provides business logic for project management including creation, retrieval, search, and membership operations.
public class ProjectService : IProjectService
- Inheritance
-
ProjectService
- Implements
- Inherited Members
Remarks
This service handles all project-related operations:
- Project creation with category, status, skills, and builder tags
- Project retrieval with owner and member information
- Project search with filtering and pagination
- Project membership management (joining, leaving)
- Profile photo URL mapping for owners and members (presigned URLs)
Constructors
ProjectService(IProjectRepository, IProjectMembershipRepository, IUserRepository, IS3Service, ILogger<ProjectService>)
Initializes a new instance of the ProjectService class.
public ProjectService(IProjectRepository projectRepository, IProjectMembershipRepository membershipRepository, IUserRepository userRepository, IS3Service s3Service, ILogger<ProjectService> logger)
Parameters
projectRepositoryIProjectRepositoryRepository for project data access operations.
membershipRepositoryIProjectMembershipRepositoryRepository for project membership data access operations.
userRepositoryIUserRepositoryRepository for user data access operations.
s3ServiceIS3ServiceService for S3 operations including presigned URL generation.
loggerILogger<ProjectService>Logger for recording service operations and errors.
Methods
CreateProjectAsync(Guid, CreateProjectRequest, CancellationToken)
Creates a new project with the specified user as the owner.
public Task<ProjectDto> CreateProjectAsync(Guid userId, CreateProjectRequest request, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user creating the project (becomes the owner).
requestCreateProjectRequestThe project creation request containing project details, category, skills, and builder tags.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProjectDto>
A ProjectDto representing the created project.
Remarks
This method performs the following operations:
- Validates the project category (must match ProjectCategory enum)
- Parses project status (defaults to "Idea" if not provided or invalid)
- Creates the project entity with owner relationship
- Associates builder tags and skills with the project
- Persists the project to the database
The project owner is automatically set to the creating user. Builder tags and skills are validated to ensure they exist before association.
Exceptions
- Exception
Thrown when the project category is invalid or other validation errors occur.
GetMyProjectsAsync(Guid, CancellationToken)
Retrieves all projects associated with a user, including projects they own and projects they are members of.
public Task<List<ProjectDto>> GetMyProjectsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose projects should be retrieved.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<List<ProjectDto>>
A list of ProjectDto objects representing all projects for the user.
Remarks
For each project, the method determines the user's role (Owner or Member) and includes pending invitation and join request counts. Profile photo URLs for owners and members are converted to presigned URLs.
GetProjectAsync(Guid, Guid, CancellationToken)
Retrieves detailed information for a specific project.
public Task<ProjectDto> GetProjectAsync(Guid projectId, Guid userId, CancellationToken cancellationToken = default)
Parameters
projectIdGuidThe unique identifier of the project to retrieve.
userIdGuidThe unique identifier of the user requesting the project (used to determine their role).
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProjectDto>
A ProjectDto containing complete project information.
Remarks
Returns project details including owner, members, skills, builder tags, and the requesting user's role. Profile photo URLs are automatically converted to presigned URLs.
Exceptions
- Exception
Thrown when the project is not found.
JoinProjectAsync(Guid, Guid, CancellationToken)
Adds a user as a member of a project.
public Task JoinProjectAsync(Guid projectId, Guid userId, CancellationToken cancellationToken = default)
Parameters
projectIdGuidThe unique identifier of the project to join.
userIdGuidThe unique identifier of the user joining the project.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Provides business logic for project management including creation, retrieval, search, and membership operations.
Remarks
This method creates an active membership for the user in the project with the "Member" role. If the user is already a member (active or inactive), the operation is idempotent and returns without error.
Project owners are automatically members of their projects and cannot join again. This method does not validate project existence - it assumes the project exists.
LeaveProjectAsync(Guid, Guid, CancellationToken)
Removes a user's membership from a project.
public Task LeaveProjectAsync(Guid projectId, Guid userId, CancellationToken cancellationToken = default)
Parameters
projectIdGuidThe unique identifier of the project to leave.
userIdGuidThe unique identifier of the user leaving the project.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Provides business logic for project management including creation, retrieval, search, and membership operations.
Remarks
This method enforces the following rules:
- Project owners cannot leave their own projects - they must transfer ownership or delete the project
- Only active memberships can be removed (pending or rejected memberships cannot be left)
- The membership is permanently deleted from the database
Exceptions
- Exception
Thrown when the project is not found, user is not a member, or membership is not active.
- UnauthorizedAccessException
Thrown when the user is the project owner (owners cannot leave their own projects).
SearchProjectsAsync(SearchProjectsRequest, CancellationToken)
Searches and retrieves projects with pagination and optional filtering.
public Task<(List<ProjectDto> Projects, int TotalCount)> SearchProjectsAsync(SearchProjectsRequest request, CancellationToken cancellationToken = default)
Parameters
requestSearchProjectsRequestSearch request containing search term, category, status, skills, pagination parameters, and optional filters.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<(List<ProjectDto> Projects, int TotalCount)>
A tuple containing the list of matching projects and the total count of projects matching the search criteria.
Remarks
This method supports two search modes:
- Advanced search: Used when skills or status filters are provided. Supports filtering by skills, status, category, and search term.
- Legacy search: Used for backward compatibility when only basic filters (category, builder tag, experience level) are provided.
Search is case-insensitive and matches project names and descriptions. Invalid category or status values are ignored. Profile photo URLs for owners and members are converted to presigned URLs. The requesting user's role is not included in search results (userId is set to Guid.Empty for mapping).