Class ProjectJoinRequestService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Provides business logic for project join request operations including creating, approving, declining, and managing join requests.
public class ProjectJoinRequestService : IProjectJoinRequestService
- Inheritance
-
ProjectJoinRequestService
- Implements
- Inherited Members
Remarks
This service handles all project join request-related operations:
- Creating join requests (users requesting to join projects)
- Approving join requests (creates active membership)
- Declining join requests
- Retrieving join requests for users and projects
- Sending email notifications for join request events
Constructors
ProjectJoinRequestService(IProjectJoinRequestRepository, IProjectRepository, IUserRepository, IProjectMembershipRepository, IUserNotificationRepository, ITokenGenerator, IProjectNotificationEmailSender, ILogger<ProjectJoinRequestService>)
Initializes a new instance of the ProjectJoinRequestService class.
public ProjectJoinRequestService(IProjectJoinRequestRepository requestRepository, IProjectRepository projectRepository, IUserRepository userRepository, IProjectMembershipRepository membershipRepository, IUserNotificationRepository notificationRepository, ITokenGenerator tokenGenerator, IProjectNotificationEmailSender emailSender, ILogger<ProjectJoinRequestService> logger)
Parameters
requestRepositoryIProjectJoinRequestRepositoryRepository for project join request data access operations.
projectRepositoryIProjectRepositoryRepository for project data access operations.
userRepositoryIUserRepositoryRepository for user data access operations.
membershipRepositoryIProjectMembershipRepositoryRepository for project membership data access operations.
notificationRepositoryIUserNotificationRepositoryRepository for user notification data access operations.
tokenGeneratorITokenGeneratorService for generating secure tokens for join request links.
emailSenderIProjectNotificationEmailSenderService for sending project join request emails.
loggerILogger<ProjectJoinRequestService>Logger for recording service operations and errors.
Methods
CancelRequestAsync(Guid, Guid, CancellationToken)
Cancels a pending join request (requester only).
public Task<ProjectJoinRequestDto> CancelRequestAsync(Guid requestId, Guid cancellerUserId, CancellationToken cancellationToken = default)
Parameters
requestIdGuidThe unique identifier of the join request to cancel.
cancellerUserIdGuidThe unique identifier of the user canceling the request (must be the requester).
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProjectJoinRequestDto>
The canceled join request DTO.
GetIncomingRequestsAsync(Guid, CancellationToken)
Retrieves all incoming join requests for projects owned by the specified user.
public Task<List<ProjectJoinRequestDto>> GetIncomingRequestsAsync(Guid ownerUserId, CancellationToken cancellationToken = default)
Parameters
ownerUserIdGuidThe unique identifier of the project owner.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<List<ProjectJoinRequestDto>>
A list of incoming join request DTOs.
GetOutgoingRequestsAsync(Guid, CancellationToken)
Retrieves all outgoing join requests created by the specified user.
public Task<List<ProjectJoinRequestDto>> GetOutgoingRequestsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user who created the requests.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<List<ProjectJoinRequestDto>>
A list of outgoing join request DTOs.
RequestJoinAsync(Guid, Guid, string?, CancellationToken)
Creates a join request for a user to join a project.
public Task<ProjectJoinRequestDto> RequestJoinAsync(Guid projectId, Guid requesterUserId, string? message, CancellationToken cancellationToken = default)
Parameters
projectIdGuidThe unique identifier of the project the user wants to join.
requesterUserIdGuidThe unique identifier of the user requesting to join.
messagestringOptional message from the requester explaining why they want to join.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProjectJoinRequestDto>
A ProjectJoinRequestDto representing the created join request.
Remarks
This method performs the following operations:
- Validates project existence
- Checks if user is already a member or has a pending membership/request
- Creates the join request with a secure token and 30-day expiration
- Sends email notification to the project owner
- Creates in-app notification for the project owner
The join request includes a secure token that allows approval/decline via email links without requiring login. If the user previously had a rejected membership, they can create a new join request.
Exceptions
- Exception
Thrown when the project is not found, user is not found, user is already a member, has a pending membership, or a pending request already exists.
RespondToRequestAsync(Guid, Guid, bool, string?, CancellationToken)
Responds to a join request (approve or decline) by the project owner.
public Task<ProjectJoinRequestDto> RespondToRequestAsync(Guid requestId, Guid ownerUserId, bool approve, string? reason, CancellationToken cancellationToken = default)
Parameters
requestIdGuidThe unique identifier of the join request to respond to.
ownerUserIdGuidThe unique identifier of the project owner responding.
approveboolTrue to approve the request; false to decline.
reasonstringOptional reason for approving or declining.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProjectJoinRequestDto>
The updated join request DTO.
RespondToRequestByTokenAsync(string, bool, string?, CancellationToken)
Responds to a join request via secure token (public endpoint, no authentication required).
public Task<ProjectJoinRequestDto> RespondToRequestByTokenAsync(string token, bool approve, string? reason, CancellationToken cancellationToken = default)
Parameters
tokenstringThe secure token from the join request email.
approveboolTrue to approve the request; false to decline.
reasonstringOptional reason for approving or declining.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ProjectJoinRequestDto>
The updated join request DTO.