Table of Contents

Class ForumRepository

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

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

public class ForumRepository : IForumRepository
Inheritance
ForumRepository
Implements
Inherited Members

Remarks

This repository manages project forum topics, messages, notification settings, and topic subscriptions. Supports soft deletion for moderation purposes and includes logging for debugging.

Constructors

ForumRepository(ApplicationDbContext, ILogger<ForumRepository>?)

Initializes a new instance of the ForumRepository class.

public ForumRepository(ApplicationDbContext context, ILogger<ForumRepository>? logger = null)

Parameters

context ApplicationDbContext

The Entity Framework database context for data access.

logger ILogger<ForumRepository>

Optional logger for debugging and tracing operations.

Methods

CreateMessageAsync(ProjectForumMessage, CancellationToken)

Creates a new forum message in the database.

public Task<ProjectForumMessage> CreateMessageAsync(ProjectForumMessage message, CancellationToken cancellationToken = default)

Parameters

message ProjectForumMessage

The forum message entity to create.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumMessage>

The created forum message entity with its generated ID.

CreateOrUpdateNotificationSettingsAsync(ProjectForumNotificationSettings, CancellationToken)

Creates or updates notification settings for a user in a project.

public Task<ProjectForumNotificationSettings> CreateOrUpdateNotificationSettingsAsync(ProjectForumNotificationSettings settings, CancellationToken cancellationToken = default)

Parameters

settings ProjectForumNotificationSettings

The notification settings entity to create or update.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumNotificationSettings>

The created or updated notification settings entity.

Remarks

If settings already exist for the project and user, they are updated. Otherwise, new settings are created.

CreateOrUpdateTopicSubscriptionAsync(ProjectForumTopicSubscription, CancellationToken)

Creates or updates a topic subscription for a user.

public Task<ProjectForumTopicSubscription> CreateOrUpdateTopicSubscriptionAsync(ProjectForumTopicSubscription subscription, CancellationToken cancellationToken = default)

Parameters

subscription ProjectForumTopicSubscription

The topic subscription entity to create or update.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumTopicSubscription>

The created or updated topic subscription entity.

Remarks

If a subscription already exists for the topic and user, it is updated. Otherwise, a new subscription is created.

CreateTopicAsync(ProjectForumTopic, CancellationToken)

Creates a new forum topic in the database.

public Task<ProjectForumTopic> CreateTopicAsync(ProjectForumTopic topic, CancellationToken cancellationToken = default)

Parameters

topic ProjectForumTopic

The forum topic entity to create.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumTopic>

The created forum topic entity with its generated ID.

GetMessageByIdAsync(Guid, CancellationToken)

Retrieves a forum message by its unique identifier.

public Task<ProjectForumMessage?> GetMessageByIdAsync(Guid messageId, CancellationToken cancellationToken = default)

Parameters

messageId Guid

The unique identifier of the message to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumMessage>

The message with Topic, CreatedByUser (with Profile), and DeletedByUser (with Profile) loaded, or null if not found.

GetMessagesByTopicIdAsync(Guid, bool, CancellationToken)

Retrieves all messages for a forum topic, optionally including soft-deleted messages.

public Task<List<ProjectForumMessage>> GetMessagesByTopicIdAsync(Guid topicId, bool includeDeleted, CancellationToken cancellationToken = default)

Parameters

topicId Guid

The unique identifier of the topic.

includeDeleted bool

Whether to include soft-deleted messages (for admin/moderation purposes).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<ProjectForumMessage>>

A list of messages with CreatedByUser (with Profile) and DeletedByUser (with Profile) loaded, ordered by creation date (oldest first).

GetNotificationSettingsAsync(Guid, Guid, CancellationToken)

Retrieves the notification settings for a user in a project.

public Task<ProjectForumNotificationSettings?> GetNotificationSettingsAsync(Guid projectId, Guid userId, CancellationToken cancellationToken = default)

Parameters

projectId Guid

The unique identifier of the project.

userId Guid

The unique identifier of the user.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumNotificationSettings>

The notification settings if found; otherwise, null.

GetSubscriptionsByTopicIdAsync(Guid, CancellationToken)

Retrieves all active subscriptions for a forum topic.

public Task<List<ProjectForumTopicSubscription>> GetSubscriptionsByTopicIdAsync(Guid topicId, CancellationToken cancellationToken = default)

Parameters

topicId Guid

The unique identifier of the topic.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<ProjectForumTopicSubscription>>

A list of active (subscribed) topic subscriptions.

GetTopicByIdAsync(Guid, CancellationToken)

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

public Task<ProjectForumTopic?> GetTopicByIdAsync(Guid topicId, CancellationToken cancellationToken = default)

Parameters

topicId Guid

The unique identifier of the topic to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumTopic>

The topic with Project, CreatedByUser (with Profile), DeletedByUser (with Profile), and Messages (with CreatedByUser and Profile) loaded, or null if not found.

GetTopicSubscriptionAsync(Guid, Guid, CancellationToken)

Retrieves the subscription status for a user to a specific forum topic.

public Task<ProjectForumTopicSubscription?> GetTopicSubscriptionAsync(Guid topicId, Guid userId, CancellationToken cancellationToken = default)

Parameters

topicId Guid

The unique identifier of the topic.

userId Guid

The unique identifier of the user.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumTopicSubscription>

The topic subscription if found; otherwise, null.

GetTopicsByProjectIdAsync(Guid, bool, CancellationToken)

Retrieves all forum topics for a project, optionally including soft-deleted topics.

public Task<List<ProjectForumTopic>> GetTopicsByProjectIdAsync(Guid projectId, bool includeDeleted, CancellationToken cancellationToken = default)

Parameters

projectId Guid

The unique identifier of the project.

includeDeleted bool

Whether to include soft-deleted topics (for admin/moderation purposes).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<ProjectForumTopic>>

A list of topics with CreatedByUser (with Profile), DeletedByUser (with Profile), and Messages loaded, ordered by creation date (newest first).

UpdateMessageAsync(ProjectForumMessage, CancellationToken)

Updates an existing forum message in the database.

public Task<ProjectForumMessage> UpdateMessageAsync(ProjectForumMessage message, CancellationToken cancellationToken = default)

Parameters

message ProjectForumMessage

The forum message entity to update.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumMessage>

The updated forum message entity.

UpdateTopicAsync(ProjectForumTopic, CancellationToken)

Updates an existing forum topic in the database.

public Task<ProjectForumTopic> UpdateTopicAsync(ProjectForumTopic topic, CancellationToken cancellationToken = default)

Parameters

topic ProjectForumTopic

The forum topic entity to update.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<ProjectForumTopic>

The updated forum topic entity.