-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddresses.rs
More file actions
34 lines (30 loc) · 836 Bytes
/
Copy pathaddresses.rs
File metadata and controls
34 lines (30 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use actix_web::{Error, HttpResponse, web};
use log::error;
use serde::Deserialize;
use crate::data::repo::addresses::get_addresses;
use crate::db::Pool;
#[derive(Deserialize)]
pub struct AddressRequest {
postcode: String,
number: Option<String>
}
pub async fn addresses(
request: web::Query<AddressRequest>,
pool: web::Data<Pool>
) -> Result<HttpResponse, Error> {
let result = web::block(move || {
get_addresses(
&pool,
&request.postcode,
request.number.as_ref().map(|n| n.as_str())
)
})
.await;
match result {
Ok(addresses) => { Ok(HttpResponse::Ok().json(addresses)) },
Err(err) => {
error!("Error while retrieving addresses: {}", err);
Ok(HttpResponse::InternalServerError().finish())
},
}
}