Table of Contents

Interface IGuildService

Namespace
FishMMO.Database.Npgsql.Services.Interfaces
Assembly
FishMMO-DB.dll

Service interface for guild management operations. Provides async methods for guild creation, deletion, and retrieval.

public interface IGuildService : IExistsByKeyAction<string>, IPersistAction<string, long?>, IDeleteByKeyAction<long>, IFetchByKeyAction<long, GuildData?>, IFetchByKeyAction<string, GuildData?>
Inherited Members

Remarks

Write operations (Persist*, Delete*) in this service use execution strategies to ensure transient database failures are automatically retried according to the retry policy configured on the DbContext. Execution is wrapped by BaseService for retries and exception mapping.

All methods return DatabaseResult or DatabaseResult<T> to provide structured error information through the DatabaseException system, helping distinguish between: - Validation failures (invalid parameters) - Business rule violations (name already exists) - Database errors (connection issues, constraint violations, timeouts) - Entity not found errors - Unexpected runtime errors

Name lookups are case-insensitive by using a normalized field (e.g. name_lowercase) in the database.

Methods

FetchExistingIdsAsync(IReadOnlyCollection<long>, CancellationToken)

Which of the given guilds still exist.

Task<DatabaseResult<IReadOnlyCollection<long>>> FetchExistingIdsAsync(IReadOnlyCollection<long> guildIds, CancellationToken cancellationToken = default)

Parameters

guildIds IReadOnlyCollection<long>

The guilds to look for.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<IReadOnlyCollection<long>>>

The subset of guildIds that still exist.

Remarks

For the scene servers' update pump. A disbanded guild's row goes, and its guild_updates row goes with it by cascade, so the pump — which only ever learned of changes through that row — never heard that the guild was gone, and its members on every other server kept a guild that no longer existed (issue #267). The pump asks this instead.

FetchNameAsync(long, CancellationToken)

Fetches the name of a guild by ID.

Task<DatabaseResult<string?>> FetchNameAsync(long guildId, CancellationToken cancellationToken = default)

Parameters

guildId long

Guild ID.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<string>>

A DatabaseResult<T> containing the guild name on success, or null if the guild was not found. Returns a failure result on database errors.

Remarks

This method uses LINQ (FirstOrDefaultAsync with AsNoTracking) and automatically benefits from the retry policy configured on the DbContext without requiring explicit execution strategy wrapping.

FetchNamesAsync(IReadOnlyList<long>, CancellationToken)

Fetches the names of a set of guilds in one query.

Task<DatabaseResult<IReadOnlyDictionary<long, string>>> FetchNamesAsync(IReadOnlyList<long> guildIds, CancellationToken cancellationToken = default)

Parameters

guildIds IReadOnlyList<long>

Guilds to resolve. Duplicates and non-positive IDs are ignored.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<IReadOnlyDictionary<long, string>>>

The name of each guild found, by ID. A guild that does not exist is absent. A failure result on database errors.

Remarks

For the scene servers' batched name lookups: every guild name a client asked for in one frame, resolved together instead of one query per guild (hot-path audit M18). Bounded internally as well as by its caller, because it answers a request a client controls the timing of.

PersistMessageOfTheDayAsync(long, string, CancellationToken)

Updates the message of the day for a guild.

Task<DatabaseResult> PersistMessageOfTheDayAsync(long guildId, string messageOfTheDay, CancellationToken cancellationToken = default)

Parameters

guildId long

Guild ID.

messageOfTheDay string

The new message of the day text.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

DatabaseResult indicating success or failure.

PersistNoticeAsync(long, string, CancellationToken)

Updates the notice text for a guild.

Task<DatabaseResult> PersistNoticeAsync(long guildId, string notice, CancellationToken cancellationToken = default)

Parameters

guildId long

Guild ID.

notice string

The new notice text.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

DatabaseResult indicating success or failure.

Remarks

The sibling of PersistMessageOfTheDayAsync(long, string, CancellationToken). The notice column has existed since the guild table was created with no way to write it; the two are kept separate because a notice is standing text about the guild while the message of the day is transient, and a single setter would force callers to read-modify-write the other.

PersistRecruitmentAsync(long, string, string, bool, CancellationToken)

Updates the guild's recruitment advertisement.

Task<DatabaseResult> PersistRecruitmentAsync(long guildId, string blurb, string tags, bool isRecruiting, CancellationToken cancellationToken = default)

Parameters

guildId long

Guild ID.

blurb string

Advertisement text shown to non-members.

tags string

Comma-separated tags; stored lower-cased for search.

isRecruiting bool

Whether the guild is listed in the directory.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

DatabaseResult indicating success or failure.

Remarks

One setter for all three fields rather than three. They are edited together from one form, and separate setters would make "stop recruiting" a two-write operation with a window in which the guild is listed with a blurb it has just withdrawn.