feat(admin): overview dashboard sections + system temperature/load sensors (0.85.0) (#11)
All checks were successful
deploy / test-backend (push) Successful in 25m9s
deploy / test-frontend (push) Successful in 10m13s
deploy / build-and-push (push) Successful in 10m25s
deploy / deploy (push) Successful in 12s

This commit was merged in pull request #11.
This commit is contained in:
2026-06-16 18:46:28 +00:00
parent 8445f338f6
commit cde4aca98b
17 changed files with 1270 additions and 59 deletions

View File

@@ -1,11 +1,31 @@
//! User persistence.
use chrono::{DateTime, Utc};
use sqlx::PgPool;
use uuid::Uuid;
use crate::domain::User;
use crate::error::{AppError, AppResult};
/// `(total, admins)` user counts for the admin overview dashboard.
pub async fn counts(pool: &PgPool) -> AppResult<(i64, i64)> {
let row: (i64, i64) = sqlx::query_as(
"SELECT COUNT(*)::bigint, COUNT(*) FILTER (WHERE is_admin)::bigint FROM users",
)
.fetch_one(pool)
.await?;
Ok(row)
}
/// Most recently created user (username, created_at), if any exist.
pub async fn newest(pool: &PgPool) -> AppResult<Option<(String, DateTime<Utc>)>> {
let row: Option<(String, DateTime<Utc>)> =
sqlx::query_as("SELECT username, created_at FROM users ORDER BY created_at DESC LIMIT 1")
.fetch_optional(pool)
.await?;
Ok(row)
}
pub async fn create(pool: &PgPool, username: &str, password_hash: &str) -> AppResult<User> {
let result = sqlx::query_as::<_, User>(
r#"