feat(signup): seed tutorial gifts as ViewerPresent rows on /tool/signup

This commit is contained in:
gamer147
2026-06-08 20:34:48 -04:00
parent f991ef762f
commit 2ce399ff87

View File

@@ -3,6 +3,7 @@ using Npgsql;
using SVSim.Database.Enums;
using SVSim.Database.Models;
using SVSim.Database.Models.Config;
using SVSim.Database.SeedData;
using SVSim.Database.Services;
namespace SVSim.Database.Repositories.Viewer;
@@ -110,6 +111,29 @@ public class ViewerRepository : IViewerRepository
var viewer = await BuildDefaultViewer("");
viewer.Udid = udid;
_dbContext.Set<Models.Viewer>().Add(viewer);
// Eager-seed the tutorial gifts so the inbox is populated by the time the tutorial
// walks the user to it (which happens AFTER initial battles, per the gift-inbox
// design). The unique (ViewerId, PresentId) index is the backstop against
// double-seeding on a retried signup. Both inserts commit in a single SaveChanges.
var createdAt = DateTime.UtcNow;
foreach (var spec in TutorialPresents.All)
{
_dbContext.Set<ViewerPresent>().Add(new ViewerPresent
{
Viewer = viewer, // EF wires up ViewerId via the nav after Insert
PresentId = spec.PresentId,
Status = PresentStatus.Unclaimed,
RewardType = spec.RewardType,
RewardDetailId = spec.RewardDetailId,
RewardCount = spec.RewardCount,
ItemType = spec.ItemType,
Message = spec.Message,
CreatedAt = createdAt,
Source = "tutorial",
});
}
try
{
await _dbContext.SaveChangesAsync();