add `/<uuid> route + backend handling

This commit is contained in:
2025-08-02 19:11:39 +02:00
parent 9badb4a4ad
commit 96a9ab361a
10 changed files with 116 additions and 50 deletions

View File

@@ -1,7 +1,7 @@
use crate::{client_id, page::new, Backend};
use crate::{page::new, Backend};
use axum::{
extract::{Path, State},
response::{IntoResponse, Response},
response::{IntoResponse, Redirect, Response},
routing::get,
Router,
};
@@ -11,9 +11,9 @@ use std::sync::Arc;
use uuid::Uuid;
async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Response {
let (cookies, client) = client_id(cookies);
let (cookies, client) = backend.client(cookies).await;
let sightings = backend.sightings_for_user_uuid(&client).await;
let sightings = backend.sightings_for_client(&client).await;
let amount_total_cameras = backend.amount_total_cameras().await;
let markup = new(html! {
@@ -44,25 +44,25 @@ async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Respo
(cookies, markup).into_response()
}
async fn game(cookies: CookieJar, Path(uuid): Path<String>) -> Response {
let (cookies, client) = client_id(cookies);
async fn game(
State(backend): State<Arc<Backend>>,
cookies: CookieJar,
Path(uuid): Path<String>,
) -> Result<Redirect, Response> {
let (cookies, client) = backend.client(cookies).await;
let Ok(uuid) = Uuid::parse_str(&uuid) else {
return not_found().await.into_response();
return Err(not_found().await.into_response());
};
let markup = new(html! {
hgroup {
h1 { "Digital Shadows" (PreEscaped("&mdash;")) "Who finds the most cameras?" }
h2 {
(client)
" found camera "
(uuid)
}
}
});
let Some(camera) = backend.camera_by_uuid(uuid).await else {
return Err(not_found().await.into_response());
};
(cookies, markup).into_response()
let succ = backend.client_found_camera(&client, &camera).await;
// TODO: show succ/err based on succ
Ok(Redirect::to("/game"))
}
async fn not_found() -> Markup {