Shared state

This commit is contained in:
Andras Schmelczer 2026-03-17 21:08:32 +00:00
parent 53fff3efaa
commit 15fa09430b
25 changed files with 174 additions and 215 deletions

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use axum::extract::{Path, Query};
use axum::extract::{Path, Query, State};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Json};
use axum::Extension;
@ -19,7 +19,7 @@ use crate::parsing::{
bounds_intersect, parse_field_indices, parse_filters, require_bounds, row_passes_filters,
};
use crate::routes::travel_time::{parse_optional_travel, TravelTimeAgg};
use crate::state::AppState;
use crate::state::SharedState;
use crate::utils::normalize_postcode;
#[derive(Serialize)]
@ -40,10 +40,11 @@ pub struct PostcodeParams {
}
pub async fn get_postcodes(
state: Arc<AppState>,
State(shared): State<Arc<SharedState>>,
Extension(user): Extension<OptionalUser>,
Query(params): Query<PostcodeParams>,
) -> Result<Json<PostcodesResponse>, axum::response::Response> {
let state = shared.load_state();
let (south, west, north, east) =
require_bounds(params.bounds).map_err(IntoResponse::into_response)?;
@ -312,9 +313,10 @@ pub async fn get_postcodes(
/// Look up a single postcode and return its centroid coordinates and geometry.
pub async fn get_postcode_lookup(
state: Arc<AppState>,
State(shared): State<Arc<SharedState>>,
Path(postcode): Path<String>,
) -> Result<Json<Value>, StatusCode> {
let state = shared.load_state();
let normalized = normalize_postcode(&postcode);
let postcode_data = &state.postcode_data;