feat: Phase 1 — core game loop complete

New endpoints:
- GET  /cards/:card_id       single card lookup
- POST /packs/buy            purchase pack with coins
- POST /objectives/claim     claim completed objective reward
- GET  /matches              match history (limit/mode query params)
- GET  /sbc/:sbc_id          single SBC lookup

Card pool expanded:
- Bronze: 11 → 30 cards (19 nations)
- Silver: 0 → 20 cards (20 nations)
- Rare Gold: 0 → 10 cards (10 nations)

SBC pool expanded:
- Added 5 new SBCs (tri_nations, silver_to_gold, league_loyalty,
  african_stars, gold_standard)

Infrastructure:
- SQLite WAL mode enabled on pool init
- Foreign key enforcement enabled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
funman300
2026-06-25 15:25:30 -07:00
parent 1ffe0ffa9f
commit 34bce2ce75
14 changed files with 378 additions and 196 deletions
+55 -2
View File
@@ -1,7 +1,9 @@
use crate::{
db::Pool,
error::AppResult,
models::objective::{ObjectiveDefinition, ObjectiveProgress, ObjectiveWithProgress},
error::{AppError, AppResult},
models::objective::{
ClaimRewardResult, ObjectiveDefinition, ObjectiveProgress, ObjectiveWithProgress,
},
};
use anyhow::Context;
use std::path::Path;
@@ -120,3 +122,54 @@ pub async fn increment_metric(
Ok(completed_ids)
}
pub async fn claim_objective(
pool: &Pool,
profile_id: &str,
club_id: &str,
defs: &[ObjectiveDefinition],
objective_id: &str,
) -> AppResult<ClaimRewardResult> {
let prog = sqlx::query_as::<_, ObjectiveProgress>(
"SELECT id, profile_id, objective_id, current, completed, claimed, updated_at FROM objective_progress WHERE profile_id = ? AND objective_id = ?"
)
.bind(profile_id)
.bind(objective_id)
.fetch_optional(pool)
.await?
.ok_or_else(|| AppError::NotFound("objective not started yet".into()))?;
if !prog.completed {
return Err(AppError::BadRequest("objective not completed yet".into()));
}
if prog.claimed {
return Err(AppError::Conflict("reward already claimed".into()));
}
let def = defs
.iter()
.find(|d| d.id == objective_id)
.ok_or_else(|| AppError::NotFound(format!("objective '{objective_id}' not found")))?;
sqlx::query("UPDATE objective_progress SET claimed = 1 WHERE id = ?")
.bind(&prog.id)
.execute(pool)
.await?;
if def.reward_coins > 0 {
crate::services::club::add_coins(pool, club_id, def.reward_coins).await?;
}
if def.reward_xp > 0 {
crate::services::profile::add_xp(pool, profile_id, def.reward_xp).await?;
}
if let Some(pack_id) = &def.reward_pack_id {
crate::services::pack::grant_pack(pool, club_id, pack_id).await?;
}
Ok(ClaimRewardResult {
objective_id: objective_id.to_string(),
coins_granted: def.reward_coins,
xp_granted: def.reward_xp,
pack_granted: def.reward_pack_id.clone(),
})
}
+17
View File
@@ -133,6 +133,23 @@ pub async fn open_pack(
})
}
pub async fn buy_pack(
pool: &Pool,
pack_defs: &[PackDefinition],
club_id: &str,
definition_id: &str,
) -> AppResult<Pack> {
let def = pack_defs
.iter()
.find(|d| d.id == definition_id)
.ok_or_else(|| {
AppError::NotFound(format!("pack definition '{definition_id}' not found"))
})?;
crate::services::club::spend_coins(pool, club_id, def.cost_coins).await?;
grant_pack(pool, club_id, definition_id).await
}
pub async fn get_unopened_packs(pool: &Pool, club_id: &str) -> AppResult<Vec<Pack>> {
let packs = sqlx::query_as::<_, Pack>(
"SELECT id, club_id, definition_id, opened, created_at FROM packs WHERE club_id = ? AND opened = 0"