feat(bp): /battle_pass/item_list — derives product per active season
Adds BattlePassSalesPeriodInfoDto, BattlePassProductDto, BattlePassItemListResponse DTOs, GetItemListAsync on BattlePassService (one product if not premium + CanPurchase, empty if already premium or off-season), and the /battle_pass/item_list controller action. 2 new integration tests; all 408 pass.
This commit is contained in:
@@ -28,4 +28,14 @@ public class BattlePassController : SVSimController
|
||||
if (info is null) return Ok(new { }); // off-season: empty payload
|
||||
return Ok(info);
|
||||
}
|
||||
|
||||
[HttpPost("item_list")]
|
||||
public async Task<IActionResult> ItemList(BaseRequest request, CancellationToken ct)
|
||||
{
|
||||
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
|
||||
|
||||
var list = await _battlePass.GetItemListAsync(viewerId, ct);
|
||||
if (list is null) return Ok(new { });
|
||||
return Ok(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using MessagePack;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.BattlePass;
|
||||
|
||||
/// <summary>
|
||||
/// /battle_pass/item_list response (Wizard/BattlePassPurchaseInfoTask.cs:23-44).
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class BattlePassItemListResponse
|
||||
{
|
||||
[JsonPropertyName("premium_pass_description")]
|
||||
[Key("premium_pass_description")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public string PremiumPassDescription { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("sales_period_info")]
|
||||
[Key("sales_period_info")]
|
||||
public BattlePassSalesPeriodInfoDto? SalesPeriodInfo { get; set; }
|
||||
|
||||
[JsonPropertyName("products")]
|
||||
[Key("products")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public List<BattlePassProductDto> Products { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using MessagePack;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.BattlePass;
|
||||
|
||||
/// <summary>
|
||||
/// One product in /battle_pass/item_list.products[] (Wizard/BattlePassPurchaseInfoTask.cs:32-43).
|
||||
/// Numerics on this DTO are numeric on the wire (the client uses .ToInt() and the captured
|
||||
/// shape isn't string-typed here).
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class BattlePassProductDto
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
[Key("id")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("season_id")]
|
||||
[Key("season_id")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public int SeasonId { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
[Key("name")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("price_crystal")]
|
||||
[Key("price_crystal")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public int PriceCrystal { get; set; }
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
[Key("description")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public string Description { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("sales_period_info")]
|
||||
[Key("sales_period_info")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public BattlePassSalesPeriodInfoDto SalesPeriodInfo { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using MessagePack;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.BattlePass;
|
||||
|
||||
/// <summary>
|
||||
/// sales_period_info on /battle_pass/item_list (Wizard/BattlePassPurchaseInfoTask.cs:26-29).
|
||||
/// Only sales_period_time is read by the client; other fields are unused but allowed.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class BattlePassSalesPeriodInfoDto
|
||||
{
|
||||
[JsonPropertyName("sales_period_time")]
|
||||
[Key("sales_period_time")]
|
||||
public string? SalesPeriodTime { get; set; }
|
||||
}
|
||||
@@ -94,6 +94,44 @@ public sealed class BattlePassService : IBattlePassService
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BattlePassItemListResponse?> GetItemListAsync(long viewerId, CancellationToken ct)
|
||||
{
|
||||
var now = _time.GetUtcNow();
|
||||
var season = await _bp.GetActiveSeasonAsync(now, ct);
|
||||
if (season is null) return null;
|
||||
|
||||
var progress = await _viewerBp.GetOrCreateProgressAsync(viewerId, season.Id, ct);
|
||||
|
||||
var response = new BattlePassItemListResponse
|
||||
{
|
||||
PremiumPassDescription = season.Description,
|
||||
SalesPeriodInfo = new BattlePassSalesPeriodInfoDto
|
||||
{
|
||||
SalesPeriodTime = FormatWireDate(season.EndDate),
|
||||
},
|
||||
Products = new List<BattlePassProductDto>(),
|
||||
};
|
||||
|
||||
// One product per active season; empty if viewer is already premium.
|
||||
if (!progress.IsPremium && season.CanPurchase)
|
||||
{
|
||||
response.Products.Add(new BattlePassProductDto
|
||||
{
|
||||
Id = season.Id * 1000,
|
||||
SeasonId = season.Id,
|
||||
Name = $"{season.Name} Premium Pass",
|
||||
PriceCrystal = season.PriceCrystal,
|
||||
Description = season.Description,
|
||||
SalesPeriodInfo = new BattlePassSalesPeriodInfoDto
|
||||
{
|
||||
SalesPeriodTime = FormatWireDate(season.EndDate),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
internal static int ComputeLevel(IReadOnlyList<BattlePassLevelEntry> curve, int point)
|
||||
{
|
||||
if (curve.Count == 0) return 1;
|
||||
|
||||
@@ -13,4 +13,10 @@ public interface IBattlePassService
|
||||
/// (controller emits empty body in that case).
|
||||
/// </summary>
|
||||
Task<BattlePassInfoResponse?> GetInfoAsync(long viewerId, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// /battle_pass/item_list payload. Returns one product per active season; empty products
|
||||
/// array if the viewer already owns premium for the active season. Null when no active season.
|
||||
/// </summary>
|
||||
Task<BattlePassItemListResponse?> GetItemListAsync(long viewerId, CancellationToken ct);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user