code: implementing trait based repository

This commit is contained in:
2023-12-31 13:43:18 +01:00
parent e3e8e55bf6
commit c8aefcc0bb
4 changed files with 18 additions and 4 deletions

View File

@@ -10,4 +10,4 @@ pub mod views;
pub fn routes() -> Router<AppState> {
Router::new().route("/", get(views::index).post(views::index_action))
}
*/
*/

View File

@@ -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(),
}
}