fix redirects; start draft of rating page

This commit is contained in:
Philipp Hofer 2025-04-08 20:45:41 +02:00
parent bacce1c55a
commit 9a347d429b
6 changed files with 46 additions and 3 deletions

View File

@ -11,6 +11,7 @@
- [x] Route_station - [x] Route_station
- [x] Team - [x] Team
- [ ] Rating view - [ ] Rating view
- [ ] auth for stations -> cookie?
- [ ] Highscore list - [ ] Highscore list
## Fancy features ## Fancy features

View File

@ -17,7 +17,7 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
let content = html! { let content = html! {
h1 { h1 {
a href="/admin/" { "↩️" } a href="/admin" { "↩️" }
"Routen" "Routen"
} }
article { article {

View File

@ -415,7 +415,7 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
let content = html! { let content = html! {
h1 { h1 {
a href="/admin/" { "↩️" } a href="/admin" { "↩️" }
(t!("stations")) (t!("stations"))
} }
article { article {

View File

@ -454,7 +454,7 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
let content = html! { let content = html! {
h1 { h1 {
a href="/admin/" { "↩️" } a href="/admin" { "↩️" }
"Teams" "Teams"
} }
article { article {

View File

@ -3,6 +3,7 @@ extern crate rust_i18n;
i18n!("locales", fallback = "de-AT"); i18n!("locales", fallback = "de-AT");
use admin::station::Station;
use axum::{body::Body, response::Response, routing::get, Router}; use axum::{body::Body, response::Response, routing::get, Router};
use partials::page; use partials::page;
use sqlx::SqlitePool; use sqlx::SqlitePool;
@ -12,6 +13,7 @@ use tower_sessions::{MemoryStore, SessionManagerLayer};
pub(crate) mod admin; pub(crate) mod admin;
mod partials; mod partials;
pub(crate) mod station;
pub(crate) fn pl(amount: usize, single: &str, append: &str) -> String { pub(crate) fn pl(amount: usize, single: &str, append: &str) -> String {
if amount == 1 { if amount == 1 {
@ -106,6 +108,7 @@ pub async fn start(listener: TcpListener, db: SqlitePool) {
let session_layer = SessionManagerLayer::new(session_store); let session_layer = SessionManagerLayer::new(session_store);
let app = Router::new() let app = Router::new()
.nest("/s", station::routes()) // TODO: maybe switch to "/"
.nest("/admin", admin::routes()) .nest("/admin", admin::routes())
.route("/pico.css", get(serve_pico_css)) .route("/pico.css", get(serve_pico_css))
.route("/style.css", get(serve_my_css)) .route("/style.css", get(serve_my_css))

39
src/station.rs Normal file
View File

@ -0,0 +1,39 @@
use crate::{partials, Station};
use axum::{extract::State, response::IntoResponse, routing::get, Router};
use maud::{html, Markup};
use sqlx::SqlitePool;
use std::sync::Arc;
use tower_sessions::Session;
async fn station_picker(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
let stations = Station::all(&db).await;
let content = html! {
h1 { "Wähle deine Station" }
select onchange="window.location.href='/s/' + this.value;" {
option selected value="" {
"Deine Station..."
}
@for station in stations {
option value=(station.id) { (station.name) };
}
}
};
partials::page(content, session, false).await
}
async fn view(
State(db): State<Arc<SqlitePool>>,
session: Session,
axum::extract::Path(id): axum::extract::Path<i64>,
) -> Markup {
//let Some(route) = Route::find_by_id(&db, id).await else {
//}
todo!()
}
pub(super) fn routes() -> Router<Arc<SqlitePool>> {
Router::new()
.route("/", get(station_picker))
.route("/{id}", get(view))
}