add sqlite db; add todos :-(; show current cameras

This commit is contained in:
2025-08-02 17:46:56 +02:00
parent 3f61f675e9
commit fe89c86004
14 changed files with 1653 additions and 31 deletions

View File

@@ -1,29 +1,51 @@
use crate::{client_id, page::new};
use crate::{client_id, page::new, Backend};
use axum::{
extract::Path,
extract::{Path, State},
response::{IntoResponse, Response},
routing::get,
Router,
};
use axum_extra::extract::CookieJar;
use maud::{html, Markup, PreEscaped};
use std::sync::Arc;
use uuid::Uuid;
fn page(content: Markup) -> Markup {
new(html! {
async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Response {
let (cookies, client) = client_id(cookies);
let sightings = backend.sightings_for_user_uuid(&client).await;
let amount_total_cameras = backend.amount_total_cameras().await;
let markup = new(html! {
hgroup {
h1 { "Digital Shadows" (PreEscaped("&mdash;")) "Who finds the most cameras?" }
(content)
}
})
}
p {
mark { "TODO: Explanation of AEF / digital shadows / search game" }
}
p {
mark { "TODO: Show optional SUCC message" }
}
p {
mark { "TODO: Show optional REGISTER-NAME message" }
}
p {
"You have found "
(sightings.len())
"/"
(amount_total_cameras)
" cameras."
}
p {
mark { "TODO: High score" }
}
});
async fn index() -> Markup {
page(html! {})
(cookies, markup).into_response()
}
async fn game(cookies: CookieJar, Path(uuid): Path<String>) -> Response {
let (cookies, device) = client_id(cookies);
let (cookies, client) = client_id(cookies);
let Ok(uuid) = Uuid::parse_str(&uuid) else {
return not_found().await.into_response();
@@ -33,7 +55,7 @@ async fn game(cookies: CookieJar, Path(uuid): Path<String>) -> Response {
hgroup {
h1 { "Digital Shadows" (PreEscaped("&mdash;")) "Who finds the most cameras?" }
h2 {
(device)
(client)
" found camera "
(uuid)
}
@@ -49,7 +71,7 @@ async fn not_found() -> Markup {
})
}
pub(super) fn routes() -> Router {
pub(super) fn routes() -> Router<Arc<Backend>> {
Router::new()
.route("/game", get(index))
.route("/{*uuid}", get(game))