move url related code back to main.rs

This commit is contained in:
Dietmar Maurer 2018-11-06 09:35:11 +01:00
parent 6d77fb4063
commit 42d569c186
2 changed files with 4 additions and 10 deletions

View File

@ -1,6 +1,5 @@
use failure::*; use failure::*;
use std::collections::HashMap; use std::collections::HashMap;
use url::form_urlencoded;
use serde_json::{json, Value}; use serde_json::{json, Value};
pub type PropertyMap = HashMap<&'static str, Jss>; pub type PropertyMap = HashMap<&'static str, Jss>;
@ -126,14 +125,6 @@ pub fn parse_parameter_strings(data: &Vec<(String, String)>, schema: &Jss) -> Re
Ok(json!(null)) Ok(json!(null))
} }
pub fn parse_query(query: &str, schema: &Jss) -> Result<Value, Error> {
let raw_param: Vec<(String, String)> =
form_urlencoded::parse(query.as_bytes()).into_owned().collect();
parse_parameter_strings(&raw_param, schema)
}
#[test] #[test]
fn test_shema1() { fn test_shema1() {
let schema = Jss::Object(JssObject { let schema = Jss::Object(JssObject {

View File

@ -65,7 +65,10 @@ fn handle_request(req: Request<Body>) -> Response<Body> {
// extract param // extract param
let param = match query { let param = match query {
Some(data) => { Some(data) => {
match parse_query(data, &api_method.parameters) { let param_list: Vec<(String, String)> =
form_urlencoded::parse(data.as_bytes()).into_owned().collect();
match parse_parameter_strings(&param_list, &api_method.parameters) {
Ok(query) => query, Ok(query) => query,
Err(err) => http_error!(NOT_FOUND, format!("Unable to parse query parameters '{}' - {}", data, err)), Err(err) => http_error!(NOT_FOUND, format!("Unable to parse query parameters '{}' - {}", data, err)),
} }