feat(signup): seed tutorial gifts as ViewerPresent rows on /tool/signup
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user