From 50cd57417d6ebef6e196dd6d91faec24a1b9a281 Mon Sep 17 00:00:00 2001 From: OpenAI Date: Thu, 13 Aug 2026 10:06:11 +0000 Subject: [PATCH] show all known athletes for session on sync page --- src/db.rs | 48 +++++++++++++++++++++++++++ src/main.rs | 94 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 113 insertions(+), 29 deletions(-) diff --git a/src/db.rs b/src/db.rs index 51ef3e6..198ac33 100644 --- a/src/db.rs +++ b/src/db.rs @@ -122,6 +122,54 @@ pub async fn session_athlete(db: &PgPool, token: &str) -> Result Result> { + let hash = hash_token(token); + + let rows = sqlx::query( + r#" + SELECT DISTINCT + a.id, + a.intervals_athlete_id, + a.display_name, + a.access_token + FROM sessions s + JOIN athletes current_athlete + ON current_athlete.id = s.athlete_id + JOIN athletes a + ON a.access_token = current_athlete.access_token + WHERE s.token_hash = $1 + AND s.created_at > now() - interval '1 day' + ORDER BY a.display_name, a.intervals_athlete_id + "#, + ) + .bind(&hash) + .fetch_all(db) + .await?; + + use sqlx::Row; + + rows.into_iter() + .map(|row| { + Ok(SessionAthlete { + id: row.try_get("id")?, + intervals_athlete_id: row.try_get("intervals_athlete_id")?, + display_name: row.try_get("display_name")?, + access_token: row.try_get("access_token")?, + }) + }) + .collect() +} + /// Return the start time of the most recently imported activity /// for an athlete. /// diff --git a/src/main.rs b/src/main.rs index bd77d9f..7c124ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,11 +161,18 @@ async fn sync_index( State(state): State, jar: axum_extra::extract::cookie::CookieJar, ) -> Result, (axum::http::StatusCode, String)> { - let session = current_session_athlete(&state, &jar) - .await - .map_err(http_error)?; + let cookie = jar + .get("county_session") + .ok_or_else(|| http_error(anyhow!("not authenticated")))?; - let html = format!( + let athletes = db::session_accessible_athletes( + &state.db, + cookie.value(), + ) + .await + .map_err(http_error)?; + + let mut html = String::from( r#" @@ -174,63 +181,92 @@ async fn sync_index( content="width=device-width,initial-scale=1"> Sync · Landkreis-Sprints

Synchronisation

+"#, + ); -
+ if athletes.is_empty() { + html.push_str( + r#"
+ Keine für diesen Authentication-Token bekannten Athleten. +
"#, + ); + } else { + html.push_str(&format!( + r#"
+ {} Athlet{} für diesen Authentication-Token bekannt. +
+
"#, + athletes.len(), + if athletes.len() == 1 { "" } else { "en" }, + )); + + for athlete in athletes { + html.push_str(&format!( + r#"

{}

-
- Intervals.icu Athlete: {} -
- +
Intervals.icu: {}

- + Aktivitäten anzeigen

-
+
"#, + html::escape(&athlete.display_name), + html::escape(&athlete.intervals_athlete_id), + url_segment(&athlete.intervals_athlete_id), + )); + } -

+ html.push_str("

"); + } + + html.push_str( + r#"

← Leaderboard

"#, - html::escape(&session.display_name), - html::escape(&session.intervals_athlete_id), - url_segment(&session.intervals_athlete_id), ); Ok(Html(html))