use axum::{extract::State, routing::get, Router}; use maud::{html, Markup}; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, SqlitePool}; use std::sync::Arc; #[derive(FromRow, Debug, Serialize, Deserialize)] struct Station { id: u64, name: String, amount_people: u8, last_login: Option, // TODO use proper timestamp (NaiveDateTime?) pw: String, lat: Option, lng: Option, } impl Station { async fn all(db: &SqlitePool) -> Vec { sqlx::query_as::<_, Self>( "SELECT id, name, amount_people, last_login, pw, lat, lng FROM station;", ) .fetch_all(db) .await .unwrap() } } async fn get_stations(State(db): State>) -> Markup { let all = Station::all(&db).await; let mut ret = String::new(); for a in all { ret.push_str(&a.name); } html! { div { (ret) } } } pub(super) fn routes() -> Router> { Router::new().route("/", get(get_stations)) }