code: implementing trait based repository

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

5
Cargo.lock generated
View File

@ -1621,6 +1621,7 @@ dependencies = [
"rust-embed",
"sea-orm",
"serde",
"serde_json",
"sqlformat",
"tokio",
]
@ -2603,9 +2604,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.107"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",

View File

@ -46,3 +46,4 @@ tokio = { version = "1.32.0", features = ["full"] }
dunce = "1.0.4"
log = "0.4.20"
env_logger = "0.10.1"
serde_json = "1.0.108"

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