Consolidation
This commit is contained in:
@@ -59,6 +59,9 @@ public class CardInventoryRepository : ICardInventoryRepository
|
||||
totalVials += (ulong)owned.Card.CollectionInfo!.DustReward * (ulong)num;
|
||||
postCounts[cardId] = owned.Count;
|
||||
}
|
||||
// Direct credit (not via RewardGrantService.ApplyAsync) because destruct is a debit-pair
|
||||
// operation (destroy cards + credit vials) handled atomically here. ApplyAsync is the
|
||||
// standard path for one-shot reward grants — see RewardGrantService for that pattern.
|
||||
viewer.Currency.RedEther += totalVials;
|
||||
|
||||
// Deck auto-strip: any deck holding more copies of a destructed card than the viewer now owns
|
||||
|
||||
@@ -9,5 +9,4 @@ public interface IPackRepository
|
||||
Task<Dictionary<int, ViewerPackOpenCount>> GetOpenCountsForViewer(long viewerId);
|
||||
Task IncrementOpenCount(long viewerId, int parentGachaId, int by);
|
||||
Task MarkDailyFreeUsed(long viewerId, int parentGachaId, DateTime when);
|
||||
Task GrantCardsToViewer(long viewerId, IEnumerable<long> cardIds);
|
||||
}
|
||||
|
||||
@@ -63,28 +63,4 @@ public class PackRepository : IPackRepository
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task GrantCardsToViewer(long viewerId, IEnumerable<long> cardIds)
|
||||
{
|
||||
var viewer = await _db.Viewers
|
||||
.Include(v => v.Cards).ThenInclude(c => c.Card)
|
||||
.FirstAsync(v => v.Id == viewerId);
|
||||
|
||||
var byId = viewer.Cards.ToDictionary(c => c.Card.Id);
|
||||
foreach (var grp in cardIds.GroupBy(id => id))
|
||||
{
|
||||
if (byId.TryGetValue(grp.Key, out var existing))
|
||||
{
|
||||
existing.Count += grp.Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Look up the card by id and attach it so we don't insert a phantom Card row.
|
||||
var card = await _db.Cards.FirstAsync(c => c.Id == grp.Key);
|
||||
var owned = new OwnedCardEntry { Card = card, Count = grp.Count(), IsProtected = false };
|
||||
viewer.Cards.Add(owned);
|
||||
byId[grp.Key] = owned;
|
||||
}
|
||||
}
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user