feat(guild): service skeletons + DI
This commit is contained in:
55
SVSim.Database/Services/Guild/GuildChatService.cs
Normal file
55
SVSim.Database/Services/Guild/GuildChatService.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using SVSim.Database.Repositories.Guild;
|
||||
using SVSim.Database.Services;
|
||||
|
||||
namespace SVSim.Database.Services.Guild;
|
||||
|
||||
public sealed class GuildChatService : IGuildChatService
|
||||
{
|
||||
private readonly IGuildRepository _guilds;
|
||||
private readonly IGuildMemberRepository _members;
|
||||
private readonly IGuildInviteRepository _invites;
|
||||
private readonly IGuildJoinRequestRepository _joinRequests;
|
||||
private readonly IGuildChatMessageRepository _chatMessages;
|
||||
private readonly IGameConfigService _config;
|
||||
|
||||
public GuildChatService(
|
||||
IGuildRepository guilds,
|
||||
IGuildMemberRepository members,
|
||||
IGuildInviteRepository invites,
|
||||
IGuildJoinRequestRepository joinRequests,
|
||||
IGuildChatMessageRepository chatMessages,
|
||||
IGameConfigService config)
|
||||
{
|
||||
_guilds = guilds;
|
||||
_members = members;
|
||||
_invites = invites;
|
||||
_joinRequests = joinRequests;
|
||||
_chatMessages = chatMessages;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public Task<ChatWindow> GetWindowAsync(long viewerId, int startMessageId, int direction, int waitIntervalHint, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ChatPostResult> PostTextOrStampAsync(long viewerId, int type, string message, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ChatPostResult> PostDeckAsync(long viewerId, string deckPayloadJson, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<bool> DeleteDeckAsync(long viewerId, int messageId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ChatPostResult> PostReplayAsync(long viewerId, string replayPayloadJson, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<string?> GetReplayDetailAsync(long viewerId, int messageId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<string?> GetDeckLogAsync(long viewerId, int messageId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
// No-op skeleton — will be wired in Phase 5.
|
||||
public Task EmitSystemEventAsync(int guildId, long actorViewerId, Entities.Guild.GuildChatMessageType type, string? body = null, CancellationToken ct = default)
|
||||
=> Task.CompletedTask;
|
||||
}
|
||||
91
SVSim.Database/Services/Guild/GuildService.cs
Normal file
91
SVSim.Database/Services/Guild/GuildService.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using SVSim.Database.Repositories.Guild;
|
||||
using SVSim.Database.Services;
|
||||
|
||||
namespace SVSim.Database.Services.Guild;
|
||||
|
||||
public sealed class GuildService : IGuildService
|
||||
{
|
||||
private readonly IGuildRepository _guilds;
|
||||
private readonly IGuildMemberRepository _members;
|
||||
private readonly IGuildInviteRepository _invites;
|
||||
private readonly IGuildJoinRequestRepository _joinRequests;
|
||||
private readonly IGuildChatMessageRepository _chatMessages;
|
||||
private readonly IGameConfigService _config;
|
||||
|
||||
public GuildService(
|
||||
IGuildRepository guilds,
|
||||
IGuildMemberRepository members,
|
||||
IGuildInviteRepository invites,
|
||||
IGuildJoinRequestRepository joinRequests,
|
||||
IGuildChatMessageRepository chatMessages,
|
||||
IGameConfigService config)
|
||||
{
|
||||
_guilds = guilds;
|
||||
_members = members;
|
||||
_invites = invites;
|
||||
_joinRequests = joinRequests;
|
||||
_chatMessages = chatMessages;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// Returns null so /guild/info can short-circuit to a non-joined response in Phase 1.
|
||||
public Task<GuildFullView?> GetMyGuildAsync(long viewerId, CancellationToken ct = default)
|
||||
=> Task.FromResult<GuildFullView?>(null);
|
||||
|
||||
public Task<Entities.Guild.Guild?> GetActiveAsync(int guildId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<IReadOnlyList<GuildSearchEntry>> SearchAsync(string name, int activity, int joinCondition, int memberBucket, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> CreateAsync(long viewerId, CreateGuildRequest req, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> UpdateAsync(long viewerId, UpdateGuildRequest req, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> UpdateDescriptionAsync(long viewerId, string description, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> UpdateEmblemAsync(long viewerId, long emblemId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> BreakupAsync(long viewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> InviteAsync(long callerViewerId, long targetViewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> CancelInviteAsync(long callerViewerId, long targetViewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> RejectInviteAsync(long callerViewerId, int guildId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> JoinAsync(long viewerId, int guildId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> CancelJoinRequestAsync(long viewerId, int guildId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> AcceptJoinRequestAsync(long callerViewerId, long applicantViewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> RejectJoinRequestAsync(long callerViewerId, long applicantViewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> LeaveAsync(long viewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> RemoveAsync(long callerViewerId, long targetViewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<GuildOpResult> ChangeRoleAsync(long callerViewerId, long targetViewerId, int newRoleId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<IReadOnlyList<Entities.Guild.GuildInvite>> ListPendingInvitesForMeAsync(long viewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<IReadOnlyList<Entities.Guild.GuildJoinRequest>> ListPendingJoinRequestsForMyGuildAsync(long viewerId, CancellationToken ct = default)
|
||||
=> throw new NotImplementedException();
|
||||
}
|
||||
40
SVSim.Database/Services/Guild/GuildServiceTypes.cs
Normal file
40
SVSim.Database/Services/Guild/GuildServiceTypes.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using SVSim.Database.Entities.Guild;
|
||||
|
||||
namespace SVSim.Database.Services.Guild;
|
||||
|
||||
public enum GuildOpResultCode
|
||||
{
|
||||
Ok = 0,
|
||||
NotInGuild,
|
||||
AlreadyInGuild,
|
||||
GuildNotFound,
|
||||
NameTaken,
|
||||
NameInvalid,
|
||||
MemberCapReached,
|
||||
SubLeaderCapReached,
|
||||
PermissionDenied,
|
||||
InviteNotFound,
|
||||
InviteAlreadyResolved,
|
||||
JoinRequestNotFound,
|
||||
JoinRequestAlreadyResolved,
|
||||
TargetNotInGuild,
|
||||
LeaderLeaveBlocked, // leader cannot leave while other members remain
|
||||
InvalidRoleTransition,
|
||||
}
|
||||
|
||||
public sealed record GuildOpResult(GuildOpResultCode Code, int? GuildId = null, string? Detail = null)
|
||||
{
|
||||
public static readonly GuildOpResult Ok = new(GuildOpResultCode.Ok);
|
||||
public bool IsOk => Code == GuildOpResultCode.Ok;
|
||||
}
|
||||
|
||||
public sealed record GuildFullView(
|
||||
Entities.Guild.Guild Guild,
|
||||
IReadOnlyList<GuildMember> Members,
|
||||
int JoinRequestCount,
|
||||
int InviteCount);
|
||||
|
||||
public sealed record GuildSearchEntry(Entities.Guild.Guild Guild, int MemberNum);
|
||||
|
||||
public sealed record CreateGuildRequest(string Name, int Activity, int JoinCondition);
|
||||
public sealed record UpdateGuildRequest(int? Activity, int? JoinCondition);
|
||||
18
SVSim.Database/Services/Guild/IGuildChatService.cs
Normal file
18
SVSim.Database/Services/Guild/IGuildChatService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace SVSim.Database.Services.Guild;
|
||||
|
||||
public sealed record ChatWindow(IReadOnlyList<Entities.Guild.GuildChatMessage> Messages, int WaitIntervalSeconds);
|
||||
public sealed record ChatPostResult(bool Ok, int? AssignedMessageId);
|
||||
|
||||
public interface IGuildChatService
|
||||
{
|
||||
Task<ChatWindow> GetWindowAsync(long viewerId, int startMessageId, int direction, int waitIntervalHint, CancellationToken ct = default);
|
||||
Task<ChatPostResult> PostTextOrStampAsync(long viewerId, int type, string message, CancellationToken ct = default);
|
||||
Task<ChatPostResult> PostDeckAsync(long viewerId, string deckPayloadJson, CancellationToken ct = default);
|
||||
Task<bool> DeleteDeckAsync(long viewerId, int messageId, CancellationToken ct = default);
|
||||
Task<ChatPostResult> PostReplayAsync(long viewerId, string replayPayloadJson, CancellationToken ct = default);
|
||||
Task<string?> GetReplayDetailAsync(long viewerId, int messageId, CancellationToken ct = default);
|
||||
Task<string?> GetDeckLogAsync(long viewerId, int messageId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Emit a system-event row. Called by IGuildService at create/join/leave/remove/role-change/description-change.</summary>
|
||||
Task EmitSystemEventAsync(int guildId, long actorViewerId, Entities.Guild.GuildChatMessageType type, string? body = null, CancellationToken ct = default);
|
||||
}
|
||||
40
SVSim.Database/Services/Guild/IGuildService.cs
Normal file
40
SVSim.Database/Services/Guild/IGuildService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
namespace SVSim.Database.Services.Guild;
|
||||
|
||||
/// <summary>
|
||||
/// Single dispatch surface for guild business operations. Enforces:
|
||||
/// - one viewer ≤1 guild
|
||||
/// - MaxMemberNum / MaxSubLeaderNum caps (from GuildConfig)
|
||||
/// - role-based permissions per docs/superpowers/specs/2026-06-27-guild-functionality-design.md
|
||||
/// - leader-leaves-with-members blocked
|
||||
/// - auto-routing single-member leader leave -> breakup
|
||||
/// - clear pending invites + cancel pending join_requests on successful join
|
||||
/// - emit system chat events via IGuildChatService
|
||||
/// </summary>
|
||||
public interface IGuildService
|
||||
{
|
||||
Task<GuildFullView?> GetMyGuildAsync(long viewerId, CancellationToken ct = default);
|
||||
Task<Entities.Guild.Guild?> GetActiveAsync(int guildId, CancellationToken ct = default);
|
||||
Task<IReadOnlyList<GuildSearchEntry>> SearchAsync(string name, int activity, int joinCondition, int memberBucket, CancellationToken ct = default);
|
||||
|
||||
Task<GuildOpResult> CreateAsync(long viewerId, CreateGuildRequest req, CancellationToken ct = default);
|
||||
Task<GuildOpResult> UpdateAsync(long viewerId, UpdateGuildRequest req, CancellationToken ct = default);
|
||||
Task<GuildOpResult> UpdateDescriptionAsync(long viewerId, string description, CancellationToken ct = default);
|
||||
Task<GuildOpResult> UpdateEmblemAsync(long viewerId, long emblemId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> BreakupAsync(long viewerId, CancellationToken ct = default);
|
||||
|
||||
Task<GuildOpResult> InviteAsync(long callerViewerId, long targetViewerId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> CancelInviteAsync(long callerViewerId, long targetViewerId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> RejectInviteAsync(long callerViewerId, int guildId, CancellationToken ct = default);
|
||||
|
||||
Task<GuildOpResult> JoinAsync(long viewerId, int guildId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> CancelJoinRequestAsync(long viewerId, int guildId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> AcceptJoinRequestAsync(long callerViewerId, long applicantViewerId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> RejectJoinRequestAsync(long callerViewerId, long applicantViewerId, CancellationToken ct = default);
|
||||
|
||||
Task<GuildOpResult> LeaveAsync(long viewerId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> RemoveAsync(long callerViewerId, long targetViewerId, CancellationToken ct = default);
|
||||
Task<GuildOpResult> ChangeRoleAsync(long callerViewerId, long targetViewerId, int newRoleId, CancellationToken ct = default);
|
||||
|
||||
Task<IReadOnlyList<Entities.Guild.GuildInvite>> ListPendingInvitesForMeAsync(long viewerId, CancellationToken ct = default);
|
||||
Task<IReadOnlyList<Entities.Guild.GuildJoinRequest>> ListPendingJoinRequestsForMyGuildAsync(long viewerId, CancellationToken ct = default);
|
||||
}
|
||||
@@ -121,6 +121,14 @@ public class Program
|
||||
builder.Services.AddScoped<IFriendService, FriendService>();
|
||||
builder.Services.AddScoped<IPlayedTogetherWriter, FriendService>();
|
||||
|
||||
builder.Services.AddScoped<SVSim.Database.Repositories.Guild.IGuildRepository, SVSim.Database.Repositories.Guild.GuildRepository>();
|
||||
builder.Services.AddScoped<SVSim.Database.Repositories.Guild.IGuildMemberRepository, SVSim.Database.Repositories.Guild.GuildMemberRepository>();
|
||||
builder.Services.AddScoped<SVSim.Database.Repositories.Guild.IGuildInviteRepository, SVSim.Database.Repositories.Guild.GuildInviteRepository>();
|
||||
builder.Services.AddScoped<SVSim.Database.Repositories.Guild.IGuildJoinRequestRepository, SVSim.Database.Repositories.Guild.GuildJoinRequestRepository>();
|
||||
builder.Services.AddScoped<SVSim.Database.Repositories.Guild.IGuildChatMessageRepository, SVSim.Database.Repositories.Guild.GuildChatMessageRepository>();
|
||||
builder.Services.AddScoped<SVSim.Database.Services.Guild.IGuildService, SVSim.Database.Services.Guild.GuildService>();
|
||||
builder.Services.AddScoped<SVSim.Database.Services.Guild.IGuildChatService, SVSim.Database.Services.Guild.GuildChatService>();
|
||||
|
||||
builder.Services.AddSingleton<IBattleContextStore, InMemoryBattleContextStore>();
|
||||
builder.Services.AddScoped<IBattleHistoryWriter, BattleHistoryWriter>();
|
||||
builder.Services.AddScoped<IReplayHistoryReader, ReplayHistoryReader>();
|
||||
|
||||
Reference in New Issue
Block a user