summaryrefslogtreecommitdiffstats
path: root/src/routes/dashboard.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-07-12 19:38:03 +0200
committersalmonik <salmonik@tuta.io>2026-07-12 19:38:03 +0200
commitae7ef10b67737f08a86743f687bca30a12e9e17a (patch)
tree056539ab76b801559dc8d07ee6599220e2bd8e07 /src/routes/dashboard.rs
parentarchitecture (diff)
downloadminecraft-ui-ae7ef10b67737f08a86743f687bca30a12e9e17a.tar.gz
minecraft-ui-ae7ef10b67737f08a86743f687bca30a12e9e17a.zip
first stable
Diffstat (limited to 'src/routes/dashboard.rs')
-rw-r--r--src/routes/dashboard.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/routes/dashboard.rs b/src/routes/dashboard.rs
new file mode 100644
index 0000000..7d5d3e4
--- /dev/null
+++ b/src/routes/dashboard.rs
@@ -0,0 +1,68 @@
1use askama::Template;
2use axum::{
3 Router,
4 extract::State,
5 response::{Html, IntoResponse},
6 routing::get,
7};
8
9use crate::auth::CurrentUser;
10use crate::routes::AppState;
11
12#[derive(Template)]
13#[template(path = "dashboard.html")]
14struct DashboardTemplate {
15 username: String,
16 is_superuser: bool,
17 password_change_required: bool,
18 active_instance: Option<ActiveInstanceInfo>,
19 container_state: String,
20}
21
22#[derive(Clone)]
23struct ActiveInstanceInfo {
24 name: String,
25 version: String,
26 server_type: String,
27 max_players: i32,
28}
29
30pub fn router() -> Router<AppState> {
31 Router::new().route("/", get(dashboard))
32}
33
34async fn dashboard(
35 State(state): State<AppState>,
36 CurrentUser(account): CurrentUser,
37) -> Result<impl IntoResponse, axum::response::Redirect> {
38 let (active_info, container_state) = {
39 let conn = state.db.conn();
40 let result = conn.query_row(
41 "SELECT name, version, server_type, max_players, container_state
42 FROM instances WHERE is_active = 1",
43 [],
44 |row| {
45 Ok((
46 Some(ActiveInstanceInfo {
47 name: row.get(0)?,
48 version: row.get(1)?,
49 server_type: row.get(2)?,
50 max_players: row.get(3)?,
51 }),
52 row.get::<_, String>(4)?,
53 ))
54 },
55 );
56 result.unwrap_or((None, "stopped".into()))
57 };
58
59 let template = DashboardTemplate {
60 username: account.username,
61 is_superuser: account.is_superuser,
62 password_change_required: account.password_change_required,
63 active_instance: active_info,
64 container_state,
65 };
66
67 Ok(Html(template.render().unwrap_or_default()))
68}