Tonight
This commit is contained in:
parent
28323f145e
commit
94f9c0d594
76 changed files with 3238 additions and 1230 deletions
|
|
@ -15,11 +15,15 @@ use crate::state::SharedState;
|
|||
use crate::utils::normalize_postcode;
|
||||
|
||||
use super::properties::{HexagonPropertiesResponse, Property};
|
||||
use super::travel_time::{load_travel_data, parse_optional_travel, row_passes_travel_filters};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PostcodePropertiesParams {
|
||||
pub postcode: String,
|
||||
pub filters: Option<String>,
|
||||
/// Pipe-separated travel time entries: `mode:slug|mode:slug:min:max`.
|
||||
/// Optional min:max applies as a filter (exclude properties outside range).
|
||||
pub travel: Option<String>,
|
||||
pub limit: Option<usize>,
|
||||
pub offset: Option<usize>,
|
||||
/// Exact address to rank first when opening properties from address search.
|
||||
|
|
@ -67,6 +71,8 @@ pub async fn get_postcode_properties(
|
|||
.map_err(|err| (StatusCode::BAD_REQUEST, err).into_response())?;
|
||||
let num_filters = parsed_filters.len() + parsed_enum_filters.len();
|
||||
let filters_str = params.filters;
|
||||
let travel_entries = parse_optional_travel(params.travel.as_deref())
|
||||
.map_err(|err| (StatusCode::BAD_REQUEST, err).into_response())?;
|
||||
|
||||
let postcode_str = normalized;
|
||||
let focus_address = params
|
||||
|
|
@ -83,6 +89,8 @@ pub async fn get_postcode_properties(
|
|||
let feature_names = &state.data.feature_names;
|
||||
let feature_name_to_index = &state.feature_name_to_index;
|
||||
let enum_values = &state.data.enum_values;
|
||||
let travel_data = load_travel_data(&state.travel_time_store, &travel_entries)?;
|
||||
let has_travel = !travel_entries.is_empty();
|
||||
|
||||
let offset_deg: f64 = POSTCODE_SEARCH_OFFSET;
|
||||
let min_lat = centroid_lat as f64 - offset_deg;
|
||||
|
|
@ -104,6 +112,15 @@ pub async fn get_postcode_properties(
|
|||
num_features,
|
||||
)
|
||||
{
|
||||
if has_travel
|
||||
&& !row_passes_travel_filters(
|
||||
state.data.postcode(row),
|
||||
&travel_entries,
|
||||
&travel_data,
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
matching_rows.push(row);
|
||||
}
|
||||
});
|
||||
|
|
@ -154,6 +171,7 @@ pub async fn get_postcode_properties(
|
|||
offset = page_offset,
|
||||
filters = num_filters,
|
||||
filters_raw = filters_str.as_deref().unwrap_or("-"),
|
||||
travel_entries = travel_entries.len(),
|
||||
ms = format_args!("{:.1}", elapsed.as_secs_f64() * 1000.0),
|
||||
"GET /api/postcode-properties"
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue