40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
// implementation of static repository
|
|
|
|
use super::domain::{AdminModelConfig, AdminRepository, RepositoryList};
|
|
use super::state::AdminRegistry;
|
|
use serde_json::{json, Value};
|
|
|
|
struct MyStaticRepository {}
|
|
|
|
impl AdminRepository for MyStaticRepository {
|
|
fn get_item(&self, id: usize) -> Option<Value> {
|
|
Some(json!({
|
|
"name": "Adam",
|
|
"age": id,
|
|
}))
|
|
}
|
|
|
|
fn get_list(&self) -> RepositoryList {
|
|
RepositoryList::List {
|
|
values: vec![
|
|
json!({"name": "Strange", "age": 150 }),
|
|
json!({"name": "Adam", "age": 12}),
|
|
],
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn register_example(registry: &mut AdminRegistry) {
|
|
let app_key = registry.register_app("Example App");
|
|
let repo = MyStaticRepository {};
|
|
let model_config = AdminModelConfig {
|
|
app_key: app_key,
|
|
name: "ExampleModel".to_owned(),
|
|
};
|
|
let model_result = registry.register_model(model_config, repo);
|
|
match model_result {
|
|
Err(err) => panic!("{}", err),
|
|
_ => (),
|
|
}
|
|
}
|