Skip to content

Commit

Permalink
made sure that the bbox argument follows the reverse-engineered schema
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 14, 2024
1 parent d03287a commit ec6d7af
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions server/src/maps/indoor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ pub async fn fetch_indoor_map(pool: &PgPool, id: i64) -> anyhow::Result<Geometry

Ok(value.geometry.unwrap())
}

#[derive(Deserialize)]
struct Arguments {
bbox: geo::Rect,
}

#[get("/api/maps/indoor/{id}")]
pub async fn get_indoor_map(
params: web::Path<i64>,
Expand All @@ -62,12 +56,37 @@ struct RemoteMap {
url: Url,
}

#[derive(Deserialize)]
struct Arguments {
bbox: String,
}
impl Arguments{
fn validate_bbox(&self) -> Result<geo::Rect<f64>, HttpResponse> {
let bbox: Vec<f64> = self
.bbox
.split(",")
.filter_map(|s| s.parse().ok())
.collect();
if bbox.len() != 4 {
return Err(HttpResponse::BadRequest().body("the bbox-parameter needs 4 floading point numbers with"));
}
Ok(geo::Rect::new(
geo::Coord::from((bbox[0], bbox[1])),
geo::Coord::from((bbox[2], bbox[3])),
))
}
}

#[get("/api/maps/indoor")]
pub async fn list_indoor_maps(
web::Query(args): web::Query<Arguments>,
data: web::Data<crate::AppData>,
) -> HttpResponse {
let maps = fetch_indoor_maps_inside_of(&data.pool, args.bbox.into()).await;
let bbox = match args.validate_bbox() {
Ok(bbox) => bbox,
Err(e) => return e,
};
let maps = fetch_indoor_maps_inside_of(&data.pool, bbox.into()).await;
let maps = match maps {
Ok(m) => m,
Err(e) => {
Expand Down

0 comments on commit ec6d7af

Please sign in to comment.