Revert homepage

This commit is contained in:
Andras Schmelczer 2026-05-16 20:25:53 +01:00
parent 48c13fbcdd
commit 47d89f6fad
9 changed files with 343 additions and 289 deletions

View file

@ -1,13 +1,14 @@
use std::sync::Arc;
use axum::Extension;
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::response::Json;
use axum::Extension;
use serde::{Deserialize, Serialize};
use crate::auth::OptionalUser;
use crate::data::{PlaceData, slugify};
use crate::licensing::{check_license_point, resolve_share_code};
use crate::state::SharedState;
use crate::utils::normalize_postcode;
@ -28,6 +29,29 @@ pub struct JourneyResponse {
minutes: Option<i16>,
/// Best-case (5th percentile) total travel time in minutes (transit only).
best_minutes: Option<i16>,
/// Destination coordinates from PlaceData, used by clients for unambiguous external links.
#[serde(skip_serializing_if = "Option::is_none")]
destination_lat: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
destination_lon: Option<f32>,
}
fn destination_coordinates(place_data: &PlaceData, slug: &str) -> Option<(f32, f32)> {
let best_idx = place_data
.name
.iter()
.enumerate()
.filter_map(|(idx, name)| {
(place_data.travel_destination[idx] && slugify(name) == slug).then_some(idx)
})
.min_by(|a, b| {
place_data.type_rank[*a]
.cmp(&place_data.type_rank[*b])
.then(place_data.population[*b].cmp(&place_data.population[*a]))
.then(place_data.name[*a].len().cmp(&place_data.name[*b].len()))
})?;
Some((place_data.lat[best_idx], place_data.lon[best_idx]))
}
pub async fn get_journey(
@ -72,10 +96,16 @@ pub async fn get_journey(
.and_then(|j| serde_json::from_str::<serde_json::Value>(j).ok());
let minutes = row.map(|r| r.minutes);
let best_minutes = row.and_then(|r| r.best_minutes);
let (destination_lat, destination_lon) =
destination_coordinates(&state.place_data, &query.slug)
.map(|(lat, lon)| (Some(lat), Some(lon)))
.unwrap_or((None, None));
Ok(Json(JourneyResponse {
journey,
minutes,
best_minutes,
destination_lat,
destination_lon,
}))
}