Interface IOnboardingQuizAttemptRepository
- Namespace
- Builvero.Application.Interfaces.Repositories
- Assembly
- Builvero.Application.dll
Defines the contract for onboarding quiz attempt data access operations including retrieval, creation, updates, and invalidation.
public interface IOnboardingQuizAttemptRepository
Remarks
This repository interface provides methods for managing onboarding quiz attempt entities. Users can have multiple quiz attempts, but only one active (unsubmitted) attempt at a time. Active attempts can be invalidated when starting a new quiz.
Methods
CreateAsync(OnboardingQuizAttempt, CancellationToken)
Creates a new onboarding quiz attempt entity in the database.
Task<OnboardingQuizAttempt> CreateAsync(OnboardingQuizAttempt attempt, CancellationToken cancellationToken = default)
Parameters
attemptOnboardingQuizAttemptThe quiz attempt entity to create.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<OnboardingQuizAttempt>
The created quiz attempt entity with generated ID and timestamps.
GetActiveAttemptByUserIdAsync(Guid, CancellationToken)
Retrieves the active (unsubmitted) quiz attempt for a specific user.
Task<OnboardingQuizAttempt?> GetActiveAttemptByUserIdAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<OnboardingQuizAttempt>
The active quiz attempt if found; otherwise, null.
GetByIdAsync(Guid, CancellationToken)
Retrieves an onboarding quiz attempt by its unique identifier.
Task<OnboardingQuizAttempt?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
Parameters
idGuidThe unique identifier of the quiz attempt to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<OnboardingQuizAttempt>
The quiz attempt entity if found; otherwise, null.
InvalidateActiveAttemptsAsync(Guid, CancellationToken)
Invalidates all active (unsubmitted) quiz attempts for a specific user.
Task InvalidateActiveAttemptsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
A task representing the asynchronous operation.
Remarks
This method is called when a user starts a new quiz to ensure only one active attempt exists. Invalidated attempts are marked as submitted or deleted to prevent reuse.
UpdateAsync(OnboardingQuizAttempt, CancellationToken)
Updates an existing onboarding quiz attempt entity in the database.
Task<OnboardingQuizAttempt> UpdateAsync(OnboardingQuizAttempt attempt, CancellationToken cancellationToken = default)
Parameters
attemptOnboardingQuizAttemptThe quiz attempt entity with updated values.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<OnboardingQuizAttempt>
The updated quiz attempt entity.