Admin users: site totals (users, buyers) and short unit marks
The user list shows how many users the site has and how many of them have paid at least once (live Stripe payments; test-mode buyers counted apart), independent of the search. The remaining units are short marks (K, Sz, E, ?, T) with a legend under the table, so the column fits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -73,6 +73,15 @@ pub async fn list_users(
|
||||
.bind(&pattern)
|
||||
.fetch_one(&state.db)
|
||||
.await?;
|
||||
// For the whole site, not the search: everyone, and who has paid at least
|
||||
// once (a live payment; test-mode payments counted apart).
|
||||
let (all_users, buyers, test_buyers): (i64, i64, i64) = sqlx::query_as(
|
||||
"SELECT (SELECT count(*) FROM users), count(*) FILTER (WHERE live), count(*) FILTER (WHERE NOT live) \
|
||||
FROM (SELECT c.user_id, bool_or(c.live) AS live FROM stripe_checkouts c \
|
||||
WHERE c.completed_at IS NOT NULL AND c.user_id IS NOT NULL GROUP BY c.user_id) b",
|
||||
)
|
||||
.fetch_one(&state.db)
|
||||
.await?;
|
||||
let users: Vec<Value> = rows
|
||||
.into_iter()
|
||||
.map(|(id, email, name, roles, verified, created, last_login, charts, natal, synastry, forecast, question, tarot)| {
|
||||
@@ -86,7 +95,10 @@ pub async fn list_users(
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
Ok(Json(json!({ "users": users, "total": total, "limit": limit, "offset": offset })))
|
||||
Ok(Json(json!({
|
||||
"users": users, "total": total, "limit": limit, "offset": offset,
|
||||
"stats": { "users": all_users, "buyers": buyers, "test_buyers": test_buyers },
|
||||
})))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
@@ -3208,4 +3208,32 @@ async fn the_user_list_pages_with_a_total(pool: PgPool) {
|
||||
assert_eq!((r.body["total"].as_i64(), r.body["users"].as_array().unwrap().len()), (Some(5), 2));
|
||||
let r = app.get("/v1/admin/users?q=lap&limit=3&offset=3", Some(&admin)).await;
|
||||
assert_eq!((r.body["total"].as_i64(), r.body["users"].as_array().unwrap().len()), (Some(4), 1));
|
||||
|
||||
// The counts are for the whole site, not the search. A buyer paid at least
|
||||
// once (two payments still one buyer); a test-mode payment counts apart,
|
||||
// an unfinished checkout not at all.
|
||||
let ids: Vec<uuid::Uuid> = sqlx::query_scalar("SELECT id FROM users WHERE email LIKE 'lap%' ORDER BY email")
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
for (n, (user, live, done)) in
|
||||
[(ids[0], true, true), (ids[0], true, true), (ids[1], false, true), (ids[2], true, false)]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
sqlx::query(
|
||||
"INSERT INTO stripe_checkouts (id, user_id, package, price_huf, live, completed_at) \
|
||||
VALUES ($1, $2, 'alap', 1990, $3, CASE WHEN $4 THEN now() END)",
|
||||
)
|
||||
.bind(format!("cs_test_{n}"))
|
||||
.bind(user)
|
||||
.bind(live)
|
||||
.bind(done)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
let r = app.get("/v1/admin/users?q=lap0", Some(&admin)).await;
|
||||
assert_eq!(r.body["total"].as_i64(), Some(1));
|
||||
assert_eq!(r.body["stats"], json!({ "users": 5, "buyers": 1, "test_buyers": 1 }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user