Phase 24: daily check-in system + club milestones endpoint
CI / Build, lint & test (push) Failing after 28s
CI / Build, lint & test (push) Failing after 28s
- migrations/0012_daily_checkin.sql: daily_checkins table tracking streak, coins awarded, pack granted, timestamp per profile - services/checkin.rs: get_status() (available, streak_day, next reward), claim() (idempotent same-day guard, streak logic: continue if yesterday or today, else reset; 7-day cycle with STREAK_COINS array, day-7 pack) - routes/club.rs: GET /club/checkin, POST /club/checkin, GET /club/milestones (computed from statistics, season_history, owned_cards, sbc_submissions, daily_checkins tables; no new DB tables needed) - 4 new integration tests: checkin available initially, claim awards coins, idempotent same-day, milestones endpoint structure (93 → 93+4=97 tests) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+88
-1
@@ -2,7 +2,7 @@ use crate::{
|
||||
app::AppState,
|
||||
error::AppResult,
|
||||
models::club::Club,
|
||||
services::{club as club_svc, profile as profile_svc},
|
||||
services::{checkin as checkin_svc, club as club_svc, profile as profile_svc, statistics as stats_svc},
|
||||
};
|
||||
use axum::{extract::State, Json};
|
||||
use serde::Deserialize;
|
||||
@@ -35,3 +35,90 @@ pub async fn put_club(
|
||||
.await?;
|
||||
Ok(Json(json!({ "club": updated })))
|
||||
}
|
||||
|
||||
pub async fn get_checkin_status(State(state): State<AppState>) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
let status = checkin_svc::get_status(&state.pool, &profile.id).await?;
|
||||
Ok(Json(json!({
|
||||
"available": status.available,
|
||||
"streak_day": status.streak_day,
|
||||
"next_reward_coins": status.next_reward_coins,
|
||||
"next_reward_pack": status.next_reward_pack,
|
||||
"last_checked_in": status.last_checked_in,
|
||||
})))
|
||||
}
|
||||
|
||||
pub async fn post_checkin(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?;
|
||||
let r = checkin_svc::claim(&state.pool, &profile.id, &club.id).await?;
|
||||
Ok(Json(json!({
|
||||
"coins_awarded": r.coins_awarded,
|
||||
"pack_awarded": r.pack_awarded,
|
||||
"new_streak": r.new_streak,
|
||||
"already_claimed": r.already_claimed,
|
||||
})))
|
||||
}
|
||||
|
||||
pub async fn get_milestones(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?;
|
||||
let stats = stats_svc::get_or_create(&state.pool, &profile.id).await?;
|
||||
|
||||
let seasons_completed: i64 = sqlx::query_scalar(
|
||||
"SELECT COUNT(*) FROM season_history WHERE profile_id = ?",
|
||||
)
|
||||
.bind(&profile.id)
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
|
||||
let highest_division: i64 = sqlx::query_scalar(
|
||||
"SELECT COALESCE(MIN(new_division), 10) FROM season_history WHERE profile_id = ?",
|
||||
)
|
||||
.bind(&profile.id)
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.unwrap_or(10);
|
||||
|
||||
let cards_owned: i64 = sqlx::query_scalar(
|
||||
"SELECT COUNT(*) FROM owned_cards WHERE club_id = ?",
|
||||
)
|
||||
.bind(&club.id)
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
|
||||
let sbcs_completed: i64 = sqlx::query_scalar(
|
||||
"SELECT COUNT(*) FROM sbc_submissions WHERE club_id = ? AND passed = 1",
|
||||
)
|
||||
.bind(&club.id)
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
|
||||
let total_checkins: i64 = sqlx::query_scalar(
|
||||
"SELECT COUNT(*) FROM daily_checkins WHERE profile_id = ?",
|
||||
)
|
||||
.bind(&profile.id)
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
|
||||
Ok(Json(json!({
|
||||
"total_wins": stats.matches_won,
|
||||
"total_draws": stats.matches_drawn,
|
||||
"total_losses": stats.matches_lost,
|
||||
"total_matches": stats.matches_played,
|
||||
"total_goals_scored": stats.goals_scored,
|
||||
"total_goals_conceded": stats.goals_conceded,
|
||||
"best_win_streak": stats.best_win_streak,
|
||||
"total_packs_opened": stats.packs_opened,
|
||||
"seasons_completed": seasons_completed,
|
||||
"highest_division_reached": highest_division,
|
||||
"cards_owned": cards_owned,
|
||||
"sbcs_completed": sbcs_completed,
|
||||
"total_checkins": total_checkins,
|
||||
"club_level": club.level,
|
||||
})))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user