Table of Contents

Class ProjectRepository

Namespace
Builvero.Infrastructure.Repositories
Assembly
Builvero.Infrastructure.dll

Repository implementation for project data access operations using Entity Framework Core.

public class ProjectRepository : IProjectRepository
Inheritance
ProjectRepository
Implements
Inherited Members

Remarks

This repository provides methods for querying, creating, updating, and searching projects. All queries use eager loading (Include) to fetch related entities (Owner, Memberships, BuilderTags, Skills, etc.) to avoid N+1 query problems.

Constructors

ProjectRepository(ApplicationDbContext)

Initializes a new instance of the ProjectRepository class.

public ProjectRepository(ApplicationDbContext context)

Parameters

context ApplicationDbContext

The Entity Framework database context for data access.

Methods

CreateAsync(Project, CancellationToken)

Creates a new project in the database.

public Task<Project> CreateAsync(Project project, CancellationToken cancellationToken = default)

Parameters

project Project

The project entity to create.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<Project>

The created project entity with its generated ID.

GetByIdAsync(Guid, CancellationToken)

Retrieves a project by its unique identifier with all related entities loaded.

public Task<Project?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the project to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<Project>

The project entity with Owner, Memberships, BuilderTags, Skills, Invitations, JoinRequests, and ForumTopics loaded, or null if not found.

GetByUserIdAsync(Guid, CancellationToken)

Retrieves all projects where the user is the owner or an active member.

public Task<List<Project>> GetByUserIdAsync(Guid userId, CancellationToken cancellationToken = default)

Parameters

userId Guid

The unique identifier of the user.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<Project>>

A list of projects with related entities loaded, ordered by creation date (newest first).

GetSearchCountAsync(string?, ProjectCategory?, Guid?, string?, CancellationToken)

Gets the total count of projects matching the specified search criteria.

public Task<int> GetSearchCountAsync(string? searchTerm, ProjectCategory? category, Guid? builderTagId, string? experienceLevel, CancellationToken cancellationToken = default)

Parameters

searchTerm string

Optional text to search in project name and description.

category ProjectCategory?

Optional project category filter.

builderTagId Guid?

Optional builder tag ID filter.

experienceLevel string

Optional experience level filter.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<int>

The total count of projects matching the search criteria.

GetSearchProjectsCountAsync(string?, List<Guid>?, ProjectStatus?, ProjectCategory?, CancellationToken)

Gets the total count of projects matching the advanced search criteria.

public Task<int> GetSearchProjectsCountAsync(string? text, List<Guid>? skillIds, ProjectStatus? status, ProjectCategory? category, CancellationToken cancellationToken = default)

Parameters

text string

Optional text to search in project name, short description, rich description, and description fields.

skillIds List<Guid>

Optional list of skill IDs. Projects must have ALL specified skills to match.

status ProjectStatus?

Optional project status filter.

category ProjectCategory?

Optional project category filter.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<int>

The total count of projects matching the search criteria.

SearchAsync(string?, ProjectCategory?, Guid?, string?, int, int, CancellationToken)

Searches for projects matching the specified criteria with pagination.

public Task<List<Project>> SearchAsync(string? searchTerm, ProjectCategory? category, Guid? builderTagId, string? experienceLevel, int page, int pageSize, CancellationToken cancellationToken = default)

Parameters

searchTerm string

Optional text to search in project name and description.

category ProjectCategory?

Optional project category filter.

builderTagId Guid?

Optional builder tag ID filter.

experienceLevel string

Optional experience level filter.

page int

The page number (1-based) to retrieve.

pageSize int

The number of projects per page.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<Project>>

A paginated list of projects matching the search criteria, ordered by creation date (newest first).

SearchProjectsAsync(string?, List<Guid>?, ProjectStatus?, ProjectCategory?, int, int, CancellationToken)

Searches for projects with advanced filtering including text search, skills, status, and category.

public Task<List<Project>> SearchProjectsAsync(string? text, List<Guid>? skillIds, ProjectStatus? status, ProjectCategory? category, int page, int pageSize, CancellationToken cancellationToken = default)

Parameters

text string

Optional text to search in project name, short description, rich description, and description fields.

skillIds List<Guid>

Optional list of skill IDs. Projects must have ALL specified skills to match.

status ProjectStatus?

Optional project status filter.

category ProjectCategory?

Optional project category filter.

page int

The page number (1-based) to retrieve.

pageSize int

The number of projects per page.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<Project>>

A paginated list of projects matching the search criteria, ordered by creation date (newest first).

UpdateAsync(Project, CancellationToken)

Updates an existing project in the database.

public Task<Project> UpdateAsync(Project project, CancellationToken cancellationToken = default)

Parameters

project Project

The project entity to update.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<Project>

The updated project entity.