Files
SVSimServer/SVSim.EmulatedEntrypoint/Controllers/ItemAcquireHistoryController.cs
gamer147 f9a971a546 feat(item-acquire-history): controller + DTOs
Add ItemAcquireHistoryController (POST /item_acquire_history/info) with its
three DTOs and two integration tests (ordering + empty-viewer). The endpoint
reads ViewerAcquireHistory rows written by InventoryTransaction.CommitAsync,
ordered newest-first, capped at 300. Tests access doc.RootElement.histories
directly (no envelope wrapper in the test path — middleware skips non-UnityPlayer UA).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-09 14:49:43 -04:00

47 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SVSim.Database;
using SVSim.EmulatedEntrypoint.Models.Dtos.ItemAcquireHistory;
namespace SVSim.EmulatedEntrypoint.Controllers;
[Route("item_acquire_history")]
public sealed class ItemAcquireHistoryController : SVSimController
{
private const string WireDateFormat = "yyyy-MM-dd HH:mm:ss";
private const int PageSize = 300;
private readonly SVSimDbContext _db;
public ItemAcquireHistoryController(SVSimDbContext db) => _db = db;
[HttpPost("info")]
public async Task<ActionResult<ItemAcquireHistoryInfoResponse>> Info(
[FromBody] ItemAcquireHistoryInfoRequest _,
CancellationToken ct)
{
if (!TryGetViewerId(out var viewerId)) return Unauthorized();
var rows = await _db.ViewerAcquireHistory
.Where(h => h.ViewerId == viewerId)
.OrderByDescending(h => h.AcquireTime)
.ThenByDescending(h => h.Id)
.Take(PageSize)
.AsNoTracking()
.ToListAsync(ct);
return new ItemAcquireHistoryInfoResponse
{
Histories = rows.Select(h => new ItemAcquireHistoryEntryDto
{
RewardType = h.RewardType.ToString(),
RewardDetailId = h.RewardDetailId.ToString(),
RewardCount = h.RewardCount.ToString(),
AcquireType = h.AcquireType.ToString(),
AcquireTime = h.AcquireTime.ToString(WireDateFormat),
Message = h.Message,
}).ToList(),
};
}
}