Phase 15: add GET /packs/store endpoint
CI / Build, lint & test (push) Failing after 52s

Returns all pack definitions with id, name, description, cost_coins, and
total_cards so the dashboard can render a purchasable pack store without
needing to know the definitions at compile time.

Two new tests: store listing shape and buy-then-open round-trip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
funman300
2026-06-25 17:25:37 -07:00
parent 26b8e9efef
commit 3d50da3589
3 changed files with 60 additions and 0 deletions
+1
View File
@@ -152,6 +152,7 @@ pub async fn build(pool: Pool, cfg: Config) -> Result<Router> {
get(routes::upgrades::get_chemistry_styles),
)
.route("/packs", get(routes::packs::get_packs))
.route("/packs/store", get(routes::packs::get_pack_store))
.route("/packs/history", get(routes::packs::get_pack_history))
.route("/packs/buy", post(routes::packs::post_buy_pack))
.route("/packs/open/:pack_id", post(routes::packs::post_open_pack))
+19
View File
@@ -35,6 +35,25 @@ pub async fn post_buy_pack(
))
}
/// List all purchasable pack definitions with their coin costs.
pub async fn get_pack_store(State(state): State<AppState>) -> AppResult<Json<Value>> {
let store: Vec<Value> = state
.pack_defs
.iter()
.map(|d| {
let total_cards: u8 = d.slots.iter().map(|s| s.count).sum();
json!({
"id": d.id,
"name": d.name,
"description": d.description,
"cost_coins": d.cost_coins,
"total_cards": total_cards,
})
})
.collect();
Ok(Json(json!({ "packs": store })))
}
pub async fn get_packs(State(state): State<AppState>) -> AppResult<Json<Value>> {
let profile = profile_svc::get_active_profile(&state.pool).await?;
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;