wip: checkpoint multi-game core work
This commit is contained in:
@@ -239,16 +239,30 @@ pub async fn claim_rivals_reward(
|
||||
pack_defs: &[PackDefinition],
|
||||
) -> AppResult<serde_json::Value> {
|
||||
// Fetch current season row (must exist)
|
||||
let row: Option<(i64, i64, i64)> = sqlx::query_as(
|
||||
"SELECT division, rivals_week_claimed, rivals_total_points FROM seasons WHERE profile_id = ?",
|
||||
let row: Option<(i64, i64, i64, Option<String>)> = sqlx::query_as(
|
||||
"SELECT division, rivals_week_claimed, rivals_total_points, rivals_last_claimed_at \
|
||||
FROM seasons WHERE profile_id = ?",
|
||||
)
|
||||
.bind(profile_id)
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
|
||||
let (division, week_claimed, total_pts) =
|
||||
let (division, week_claimed, total_pts, last_claimed_at) =
|
||||
row.ok_or_else(|| AppError::NotFound("no season found — play a match first".into()))?;
|
||||
|
||||
// Enforce 24-hour cooldown between weekly reward claims
|
||||
if let Some(ref last_claimed) = last_claimed_at {
|
||||
if let Ok(last_time) = chrono::DateTime::parse_from_rfc3339(last_claimed) {
|
||||
let elapsed = chrono::Utc::now() - last_time.with_timezone(&chrono::Utc);
|
||||
if elapsed < chrono::Duration::hours(24) {
|
||||
let hours_remaining = 24 - elapsed.num_hours();
|
||||
return Err(AppError::Conflict(format!(
|
||||
"rivals weekly reward already claimed; try again in ~{hours_remaining}h"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let next_week = week_claimed + 1;
|
||||
let coins = rivals_weekly_coins(division);
|
||||
let new_balance = club_svc::add_coins(pool, club_id, coins).await?;
|
||||
@@ -271,11 +285,13 @@ pub async fn claim_rivals_reward(
|
||||
None
|
||||
};
|
||||
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
sqlx::query(
|
||||
"UPDATE seasons SET rivals_week_claimed = ?, rivals_total_points = rivals_total_points + 100 \
|
||||
WHERE profile_id = ?",
|
||||
"UPDATE seasons SET rivals_week_claimed = ?, rivals_total_points = rivals_total_points + 100, \
|
||||
rivals_last_claimed_at = ? WHERE profile_id = ?",
|
||||
)
|
||||
.bind(next_week)
|
||||
.bind(&now)
|
||||
.bind(profile_id)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user