move url related code back to main.rs
This commit is contained in:
parent
6d77fb4063
commit
42d569c186
|
@ -1,6 +1,5 @@
|
|||
use failure::*;
|
||||
use std::collections::HashMap;
|
||||
use url::form_urlencoded;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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]
|
||||
fn test_shema1() {
|
||||
let schema = Jss::Object(JssObject {
|
||||
|
|
|
@ -65,7 +65,10 @@ fn handle_request(req: Request<Body>) -> Response<Body> {
|
|||
// extract param
|
||||
let param = match query {
|
||||
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(¶m_list, &api_method.parameters) {
|
||||
Ok(query) => query,
|
||||
Err(err) => http_error!(NOT_FOUND, format!("Unable to parse query parameters '{}' - {}", data, err)),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue