- ChangeRoleAsync: Leader-only role management with SubLeader cap check. Atomic leader transfer loads both member rows + Guild.LeaderViewerId in one _db.SaveChangesAsync call (no split saves). Emits ChangeLeader (6) or ChangeSubLeader (7) chat events. Same-role is no-op / returns Ok. - /guild/change_role controller: calls ChangeRoleAsync, returns full updated member list (GuildChangeRoleResponse.Members[]). - /guild/friend_list controller: calls IFriendService.GetFriendsAsync, then annotates each friend with is_join_guild from Viewer.GuildId column. - IGuildRepository.UpdateLeaderViewerIdAsync: added for completeness even though the atomic transfer path bypasses it via direct EF mutation. - Tests: 8 GuildServiceChangeRoleTests (role changes, cap, atomic transfer, no-op, permission); 3 GuildChangeRoleFriendListFlowTests (HTTP roundtrip, is_join_guild); 2 GuildWireShape tests (literal JSON shape); 1508 pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
2.1 KiB
C#
40 lines
2.1 KiB
C#
using SVSim.Database.Entities.Guild;
|
|
|
|
namespace SVSim.Database.Repositories.Guild;
|
|
|
|
public interface IGuildRepository
|
|
{
|
|
Task<Entities.Guild.Guild?> GetByIdAsync(int guildId, CancellationToken ct = default);
|
|
|
|
/// <summary>Returns guild only if not soft-deleted (BreakupAt is null).</summary>
|
|
Task<Entities.Guild.Guild?> GetActiveByIdAsync(int guildId, CancellationToken ct = default);
|
|
|
|
/// <summary>Returns guild + populated Members list (split-query).</summary>
|
|
Task<Entities.Guild.Guild?> GetWithMembersAsync(int guildId, CancellationToken ct = default);
|
|
|
|
Task<bool> NameExistsAsync(string name, CancellationToken ct = default);
|
|
|
|
Task<Entities.Guild.Guild> AddAsync(Entities.Guild.Guild g, CancellationToken ct = default);
|
|
|
|
/// <summary>Soft-delete: sets BreakupAt to UtcNow. Caller is responsible for cascading
|
|
/// hard-deletes on Members / Invites / JoinRequests / ChatMessages.</summary>
|
|
Task MarkBrokenUpAsync(int guildId, DateTime brokenUpAt, CancellationToken ct = default);
|
|
|
|
/// <summary>Filtered + bucketed search. Empty name = match-all; activity/joinCondition/bucket = 0 = any.</summary>
|
|
Task<IReadOnlyList<Entities.Guild.Guild>> SearchAsync(
|
|
string name, int activity, int joinCondition, int memberBucket,
|
|
int maxMemberCap, int resultCap, CancellationToken ct = default);
|
|
|
|
/// <summary>Updates name, activity, and/or join_condition. Only non-null fields are written.</summary>
|
|
Task UpdateActivityAndJoinConditionAsync(int guildId, int? activity, int? joinCondition, string? name = null, CancellationToken ct = default);
|
|
|
|
/// <summary>Overwrites the description field.</summary>
|
|
Task UpdateDescriptionAsync(int guildId, string description, CancellationToken ct = default);
|
|
|
|
/// <summary>Overwrites the emblem_id field.</summary>
|
|
Task UpdateEmblemAsync(int guildId, long emblemId, CancellationToken ct = default);
|
|
|
|
/// <summary>Updates LeaderViewerId on the Guild row — used by ChangeRoleAsync atomic leader transfer.</summary>
|
|
Task UpdateLeaderViewerIdAsync(int guildId, long newLeaderViewerId, CancellationToken ct = default);
|
|
}
|