Table of Contents

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
Access control: Only project owners can approve or decline join requests. Join requests expire after 30 days.

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

requestRepository IProjectJoinRequestRepository

Repository for project join request data access operations.

projectRepository IProjectRepository

Repository for project data access operations.

userRepository IUserRepository

Repository for user data access operations.

membershipRepository IProjectMembershipRepository

Repository for project membership data access operations.

notificationRepository IUserNotificationRepository

Repository for user notification data access operations.

tokenGenerator ITokenGenerator

Service for generating secure tokens for join request links.

emailSender IProjectNotificationEmailSender

Service for sending project join request emails.

logger ILogger<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

requestId Guid

The unique identifier of the join request to cancel.

cancellerUserId Guid

The unique identifier of the user canceling the request (must be the requester).

cancellationToken CancellationToken

Cancellation 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

ownerUserId Guid

The unique identifier of the project owner.

cancellationToken CancellationToken

Cancellation 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

userId Guid

The unique identifier of the user who created the requests.

cancellationToken CancellationToken

Cancellation 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

projectId Guid

The unique identifier of the project the user wants to join.

requesterUserId Guid

The unique identifier of the user requesting to join.

message string

Optional message from the requester explaining why they want to join.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectJoinRequestDto>

A ProjectJoinRequestDto representing the created join request.

Remarks

This method performs the following operations:

  1. Validates project existence
  2. Checks if user is already a member or has a pending membership/request
  3. Creates the join request with a secure token and 30-day expiration
  4. Sends email notification to the project owner
  5. 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

requestId Guid

The unique identifier of the join request to respond to.

ownerUserId Guid

The unique identifier of the project owner responding.

approve bool

True to approve the request; false to decline.

reason string

Optional reason for approving or declining.

cancellationToken CancellationToken

Cancellation 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

token string

The secure token from the join request email.

approve bool

True to approve the request; false to decline.

reason string

Optional reason for approving or declining.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectJoinRequestDto>

The updated join request DTO.