fix(guild): final-review remediation — replay_detail flat, FK on leader, transaction wraps, _db extraction
C1: replay_detail — flatten stored payload to data level. ChatReplayDetailTask.Parse() calls new ReplayDetailInfo(data) which unguardedly accesses data[battleId], data[seed], data[vid1], etc. Wrapping under replay_info key crashes the client. Controller now returns Ok(JsonElement) directly so stored battle fields are at data root. Wire-shape test added. C2: Guild.LeaderViewerId long to long?; add HasOne<Viewer> FK with OnDelete=SetNull; migration AddGuildLeaderViewerIdFk; all consumers null-guarded with ?? 0L. C3: BreakupAsync — wrap 6 destructive ops in IDbContextTransaction with InMemory fallback. C4: CommitJoinAsync — wrap member-add + viewer-guildId-set + invite/request cleanup in IDbContextTransaction with InMemory fallback. Chat event emitted after commit. I1: GuildController — remove SVSimDbContext field; inject IViewerRepository + IGuildMemberRepository. Add IGuildMemberRepository.GetViewerIdsInAGuildAsync (batch guild-membership check). All _db.Viewers / _db.GuildMembers queries replaced with repo calls. I2: GuildService — extract 3 _db.Viewers queries: GetEquippedEmblemIdAsync (CreateAsync), LoadGuildProfileBatchAsync (ListOutgoingInvitesAsync + ListPendingJoinRequestsForMyGuildAsync). Add GuildMemberProfile record with IsOfficialMarkDisplayed. GetEmblemListAsync for EmblemList. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -131,15 +131,19 @@ public sealed class GuildChatController : SVSimController
|
||||
}
|
||||
|
||||
[HttpPost("replay_detail")]
|
||||
public async Task<ActionResult<GuildChatReplayDetailResponse>> ReplayDetail([FromBody] GuildChatReplayDetailRequest req, CancellationToken ct)
|
||||
public async Task<ActionResult> ReplayDetail([FromBody] GuildChatReplayDetailRequest req, CancellationToken ct)
|
||||
{
|
||||
if (!TryGetViewerId(out var viewerId)) return Unauthorized();
|
||||
|
||||
var payloadJson = await _chat.GetReplayDetailAsync(viewerId, (int)req.MessageId, ct);
|
||||
if (payloadJson is null) return Ok(new { result_code = 2 });
|
||||
|
||||
var replayInfo = ParseJsonElementOrNull(payloadJson);
|
||||
return new GuildChatReplayDetailResponse { ReplayInfo = replayInfo };
|
||||
// ReplayDetailInfo(data) accesses data["battleId"], data["seed"], data["vid1"], etc.
|
||||
// directly without Keys.Contains guards — returning a wrapper object crashes the client.
|
||||
// The stored ReplayPayload IS the full flat battle object; emit its fields directly as
|
||||
// the data payload so data["battleId"].ToLong() etc. resolve correctly.
|
||||
var replayElement = ParseJsonElementOrNull(payloadJson);
|
||||
return replayElement.HasValue ? Ok(replayElement.Value) : Ok(new { result_code = 2 });
|
||||
}
|
||||
|
||||
[HttpPost("deck_log")]
|
||||
|
||||
Reference in New Issue
Block a user