api3/config/datastore.rs: return real data

This commit is contained in:
Dietmar Maurer 2018-12-09 10:23:19 +01:00
parent 6349ed60b4
commit b65eaac62d
2 changed files with 16 additions and 5 deletions

View File

@ -10,10 +10,9 @@ use crate::config::datastore;
fn datastore_list(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
println!("This is a test {}", param);
let config = datastore::config().unwrap();
Ok(json!({}))
let config = datastore::config()?;
Ok(config.convert_to_array("id"))
}
pub fn router() -> Router {

View File

@ -38,7 +38,7 @@ enum ParseState<'a> {
#[derive(Debug)]
pub struct SectionConfigData {
sections: HashMap<String, (String, Value)>,
pub sections: HashMap<String, (String, Value)>,
order: VecDeque<String>,
}
@ -56,6 +56,18 @@ impl SectionConfigData {
fn record_order(&mut self, section_id: &str) {
self.order.push_back(section_id.to_string());
}
pub fn convert_to_array(&self, id_prop: &str) -> Value {
let mut list: Vec<Value> = vec![];
for (section_id, (_, data)) in &self.sections {
let mut entry = data.clone();
entry.as_object_mut().unwrap().insert(id_prop.into(), section_id.clone().into());
list.push(entry);
}
list.into()
}
}
impl SectionConfig {