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
contextApplicationDbContextThe 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
projectProjectThe project entity to create.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
idGuidThe unique identifier of the project to retrieve.
cancellationTokenCancellationTokenCancellation 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
userIdGuidThe unique identifier of the user.
cancellationTokenCancellationTokenCancellation 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
searchTermstringOptional text to search in project name and description.
categoryProjectCategory?Optional project category filter.
builderTagIdGuid?Optional builder tag ID filter.
experienceLevelstringOptional experience level filter.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
textstringOptional text to search in project name, short description, rich description, and description fields.
skillIdsList<Guid>Optional list of skill IDs. Projects must have ALL specified skills to match.
statusProjectStatus?Optional project status filter.
categoryProjectCategory?Optional project category filter.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
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
searchTermstringOptional text to search in project name and description.
categoryProjectCategory?Optional project category filter.
builderTagIdGuid?Optional builder tag ID filter.
experienceLevelstringOptional experience level filter.
pageintThe page number (1-based) to retrieve.
pageSizeintThe number of projects per page.
cancellationTokenCancellationTokenCancellation 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
textstringOptional text to search in project name, short description, rich description, and description fields.
skillIdsList<Guid>Optional list of skill IDs. Projects must have ALL specified skills to match.
statusProjectStatus?Optional project status filter.
categoryProjectCategory?Optional project category filter.
pageintThe page number (1-based) to retrieve.
pageSizeintThe number of projects per page.
cancellationTokenCancellationTokenCancellation 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
projectProjectThe project entity to update.
cancellationTokenCancellationTokenCancellation token to cancel the operation.