Files
SVSimServer/SVSim.EmulatedEntrypoint/Controllers/GiftController.cs
2026-05-28 12:02:54 -04:00

77 lines
3.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SVSim.Database;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Gift;
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.Gift;
namespace SVSim.EmulatedEntrypoint.Controllers;
/// <summary>
/// Tutorial-scoped gift endpoints. We do NOT implement a generic gift system here —
/// only the /tutorial/gift_top and /tutorial/gift_receive aliases needed for the
/// step 31 → 41 reward flow. A full gift inbox is future work; if/when needed,
/// add /gift/top and /gift/receive_gift aliases to this controller.
/// </summary>
public class GiftController : SVSimController
{
/// <summary>The hardcoded tutorial gift bundle every fresh viewer sees at step 31.</summary>
public static readonly IReadOnlyList<PresentDto> TutorialGifts = new[]
{
new PresentDto { PresentId = "71478626", RewardType = "1", RewardDetailId = "0", RewardCount = "400", Message = "For completing the tutorial" },
new PresentDto { PresentId = "71478627", RewardType = "9", RewardDetailId = "0", RewardCount = "100", Message = "For completing the tutorial" },
new PresentDto { PresentId = "71478628", RewardType = "4", RewardDetailId = "1", RewardCount = "3", Message = "For completing the tutorial", ItemType = 1 },
new PresentDto { PresentId = "71478629", RewardType = "4", RewardDetailId = "80001", RewardCount = "40", Message = "For completing the tutorial", ItemType = 2 },
new PresentDto { PresentId = "71478630", RewardType = "4", RewardDetailId = "90001", RewardCount = "1", Message = "For completing the tutorial", ItemType = 2 },
};
private readonly SVSimDbContext _db;
public GiftController(SVSimDbContext db)
{
_db = db;
}
[HttpPost("/tutorial/gift_top")]
public async Task<ActionResult<GiftTopResponse>> TutorialGiftTop([FromBody] GiftTopRequest request)
{
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
var claimedList = await _db.ViewerClaimedTutorialGifts
.Where(g => g.ViewerId == viewerId)
.Select(g => g.PresentId)
.ToListAsync();
var claimed = new HashSet<string>(claimedList);
var nowString = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
var presents = TutorialGifts
.Where(p => !claimed.Contains(p.PresentId))
.Select(p => Clone(p, nowString))
.ToList();
var history = TutorialGifts
.Where(p => claimed.Contains(p.PresentId))
.Select(p => Clone(p, nowString))
.ToList();
return new GiftTopResponse
{
PresentList = presents,
PresentHistoryList = history,
LimitOverPresentList = new(),
};
}
private static PresentDto Clone(PresentDto p, string createTime) => new()
{
PresentId = p.PresentId,
RewardType = p.RewardType,
RewardDetailId = p.RewardDetailId,
RewardCount = p.RewardCount,
ConditionNumber = p.ConditionNumber,
PresentLimitType = p.PresentLimitType,
RewardLimitTime = p.RewardLimitTime,
CreateTime = createTime,
ItemType = p.ItemType,
Message = p.Message,
};
}