code: implementing trait based repository
This commit is contained in:
@@ -10,4 +10,4 @@ pub mod views;
|
||||
pub fn routes() -> Router<AppState> {
|
||||
Router::new().route("/", get(views::index).post(views::index_action))
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -4,16 +4,27 @@ use axum::{async_trait, response::IntoResponse};
|
||||
use axum::{routing::get, Router};
|
||||
use core::future::Future;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type AdminState = Arc<AdminRegistry>;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub enum RepositoryData {}
|
||||
|
||||
pub trait AdminRepository: Send + Sync {
|
||||
fn get_item(&self, id: usize) -> Option<Value>;
|
||||
fn get_list(&self) -> Value;
|
||||
}
|
||||
|
||||
// main registry.
|
||||
#[derive(Clone)]
|
||||
pub struct AdminRegistry {
|
||||
base_path: String,
|
||||
apps: HashMap<String, internal::DataNode>,
|
||||
models: HashMap<String, internal::DataNode>,
|
||||
repositories: HashMap<String, Box<dyn AdminRepository>>,
|
||||
}
|
||||
|
||||
impl AdminRegistry {
|
||||
@@ -22,6 +33,7 @@ impl AdminRegistry {
|
||||
base_path: base_path.to_owned(),
|
||||
apps: HashMap::new(),
|
||||
models: HashMap::new(),
|
||||
repositories: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user