Class CharacterAchievementService
Service for managing character achievements in the database. Provides async operations for CRUD operations on character achievement data. Uses the BaseService execution strategy for automatic retry on transient database failures. Returns DatabaseResult for consistent, safe error handling.
public sealed class CharacterAchievementService : BaseService<CharacterAchievementEntity>, ICharacterAchievementService, IPersistManyAction<CharacterAchievementData>, IPersistManyOwnedAction<CharacterAchievementData>, IDeleteByKeyVersionedAction<long>, IFetchCollectionByKeyAction<long, CharacterAchievementData>
- Inheritance
-
CharacterAchievementService
- Implements
- Inherited Members
Constructors
CharacterAchievementService(INpgsqlDbContextFactory)
Initializes a new instance of the CharacterAchievementService class.
public CharacterAchievementService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactoryFactory for creating database contexts.
Exceptions
- ArgumentNullException
Thrown when dbContextFactory is null.
Methods
DeleteAsync(long, long, CancellationToken)
Deletes the entity identified by the given key if incomingVersion is newer.
public Task<DatabaseResult> DeleteAsync(long characterId, long incomingVersion, CancellationToken cancellationToken = default)
Parameters
characterIdlongincomingVersionlongThe authoritative, monotonic version for this delete operation.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
FetchAsync(long, CancellationToken)
Fetches a collection of items for the given key.
public Task<DatabaseResult<IReadOnlyList<CharacterAchievementData>>> FetchAsync(long characterId, CancellationToken cancellationToken = default)
Parameters
characterIdlongcancellationTokenCancellationTokenToken to cancel the operation.
Returns
PersistAsync(IEnumerable<CharacterAchievementData>, CancellationToken)
Persists the provided items.
public Task<DatabaseResult<BulkWriteResult>> PersistAsync(IEnumerable<CharacterAchievementData> achievements, CancellationToken cancellationToken = default)
Parameters
achievementsIEnumerable<CharacterAchievementData>cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult<BulkWriteResult>>
What the write actually did, or a failure.
Remarks
A successful result does not mean every supplied row was written. Batched writes are version-gated and the service filters what it cannot act on, so the outcome carries counts rather than a bare boolean — see BulkWriteResult, which explains which discrepancies a caller should care about and which are routine.
PersistOwnedAsync(IEnumerable<CharacterAchievementData>, IReadOnlyCollection<CharacterSessionLeaseData>, CancellationToken)
Persists the rows whose characters the writer still owns.
public Task<DatabaseResult<BulkWriteResult>> PersistOwnedAsync(IEnumerable<CharacterAchievementData> achievements, IReadOnlyCollection<CharacterSessionLeaseData> claims, CancellationToken cancellationToken = default)
Parameters
achievementsIEnumerable<CharacterAchievementData>claimsIReadOnlyCollection<CharacterSessionLeaseData>The claim held for each character the rows name, as captured with them.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult<BulkWriteResult>>
What the write did. Rows of a live character whose claim is not held are counted as Unowned (and so as filtered). The write fails with Forbidden when it could touch none of its characters for that reason, and with NotFound when none exists.