Fun changes
This commit is contained in:
parent
cd778dd088
commit
349a6c1d53
60 changed files with 1260 additions and 2600 deletions
|
|
@ -13,6 +13,7 @@ use tracing::info;
|
|||
use crate::aggregation::{Aggregator, EnumDistConfig};
|
||||
use crate::auth::OptionalUser;
|
||||
use crate::consts::MAX_CELLS_PER_REQUEST;
|
||||
use crate::pocketbase::log_user_location;
|
||||
use crate::data::travel_time::TravelData;
|
||||
use crate::licensing::check_license_bounds;
|
||||
use crate::parsing::{
|
||||
|
|
@ -339,8 +340,10 @@ pub async fn get_postcodes(
|
|||
}
|
||||
|
||||
/// Find the nearest postcode to a given lat/lng coordinate.
|
||||
/// If the user is authenticated, logs their location to PocketBase in the background.
|
||||
pub async fn get_nearest_postcode(
|
||||
State(shared): State<Arc<SharedState>>,
|
||||
Extension(user): Extension<OptionalUser>,
|
||||
Query(params): Query<NearestPostcodeParams>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
let state = shared.load_state();
|
||||
|
|
@ -368,6 +371,18 @@ pub async fn get_nearest_postcode(
|
|||
let geometry = postcode_data.geometries[idx].clone();
|
||||
let postcode = &postcode_data.postcodes[idx];
|
||||
|
||||
// Log location for authenticated users (best-effort, non-blocking)
|
||||
if let Some(ref pb_user) = user.0 {
|
||||
let state = state.clone();
|
||||
let user_id = pb_user.id.clone();
|
||||
let lat_f64 = params.lat;
|
||||
let lng_f64 = params.lng;
|
||||
let pc = postcode.clone();
|
||||
tokio::spawn(async move {
|
||||
log_user_location(&state, &user_id, lat_f64, lng_f64, &pc).await;
|
||||
});
|
||||
}
|
||||
|
||||
info!(postcode = %postcode, "GET /api/nearest-postcode");
|
||||
Ok(Json(serde_json::json!({
|
||||
"postcode": postcode,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue