Skip to content

Commit

Permalink
Don't return empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Nov 19, 2023
1 parent 0a6b254 commit 6259454
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,25 @@ async fn craftsmen_search_detailed(
let postalcode: u32 = path.into_inner().parse().unwrap();
let map = data.read().unwrap();

let postcode_info = postcode_info_map.read().unwrap();
let postcode_details = postcode_info.get(&postalcode);

let Some(mut service_providers) = (match query.sort.as_deref() {
Some("distance") => map.ranked_by_distance(postalcode),
Some("profile") => map.ranked_by_profile(postalcode),
_ => map.ranked_by_score(postalcode),
}) else {
return Ok(HttpResponse::Ok()
.content_type("application/json")
.body("[]".to_string()));
.body(
serde_json::to_string(&DetailedResponse {
has_more: false,
total_count: 0,
results: vec![],
postcode_info: postcode_details.map(|x| x.clone()),
})
.unwrap(),
));
};

let total_count = service_providers.len();
Expand All @@ -158,9 +169,6 @@ async fn craftsmen_search_detailed(
.map(|sp| sp.unwrap())
.collect();

let postcode_info = postcode_info_map.read().unwrap();
let postcode_details = postcode_info.get(&postalcode);

Ok(HttpResponse::Ok().content_type("application/json").body(
serde_json::to_string(&DetailedResponse {
has_more,
Expand Down

0 comments on commit 6259454

Please sign in to comment.