api3/config/datastore.rs: return real data
This commit is contained in:
		@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user