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:
5018
SVSim.Database/Migrations/20260627202442_AddGuildLeaderViewerIdFk.Designer.cs
generated
Normal file
5018
SVSim.Database/Migrations/20260627202442_AddGuildLeaderViewerIdFk.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SVSim.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddGuildLeaderViewerIdFk : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<long>(
|
||||
name: "LeaderViewerId",
|
||||
table: "Guilds",
|
||||
type: "bigint",
|
||||
nullable: true,
|
||||
oldClrType: typeof(long),
|
||||
oldType: "bigint");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Guilds_LeaderViewerId",
|
||||
table: "Guilds",
|
||||
column: "LeaderViewerId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Guilds_Viewers_LeaderViewerId",
|
||||
table: "Guilds",
|
||||
column: "LeaderViewerId",
|
||||
principalTable: "Viewers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Guilds_Viewers_LeaderViewerId",
|
||||
table: "Guilds");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Guilds_LeaderViewerId",
|
||||
table: "Guilds");
|
||||
|
||||
migrationBuilder.AlterColumn<long>(
|
||||
name: "LeaderViewerId",
|
||||
table: "Guilds",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
defaultValue: 0L,
|
||||
oldClrType: typeof(long),
|
||||
oldType: "bigint",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace SVSim.Database.Migrations
|
||||
b.Property<int>("JoinCondition")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long>("LeaderViewerId")
|
||||
b.Property<long?>("LeaderViewerId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Name")
|
||||
@@ -120,6 +120,8 @@ namespace SVSim.Database.Migrations
|
||||
|
||||
b.HasKey("GuildId");
|
||||
|
||||
b.HasIndex("LeaderViewerId");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.ToTable("Guilds");
|
||||
@@ -3653,6 +3655,14 @@ namespace SVSim.Database.Migrations
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Entities.Guild.Guild", b =>
|
||||
{
|
||||
b.HasOne("SVSim.Database.Models.Viewer", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("LeaderViewerId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildChatMessage", b =>
|
||||
{
|
||||
b.HasOne("SVSim.Database.Entities.Guild.Guild", "Guild")
|
||||
|
||||
Reference in New Issue
Block a user