pub mod error;
pub mod handlers;
pub mod middleware;
pub mod models;
pub mod services;
pub mod storage;
use axum::{middleware as axum_middleware, Router};
use std::sync::Arc;
use crate::http::state::AppState;
use crate::storage::{
StorageClient, StorageOperationContextOps, StorageSchemaContextOps, StorageSyncContextOps,
};
use self::storage::SqliteStorage;
#[derive(Clone)]
pub struct WebState<
S: StorageClient
+ StorageSchemaContextOps
+ StorageSyncContextOps
+ StorageOperationContextOps
+ Clone
+ Send
+ Sync
+ 'static,
> {
pub metadata_storage: Arc<SqliteStorage>,
pub core_state: AppState<S>,
}
impl<
S: StorageClient
+ StorageSchemaContextOps
+ StorageSyncContextOps
+ StorageOperationContextOps
+ Clone
+ Send
+ Sync
+ 'static,
> WebState<S>
{
pub async fn new(storage_path: &str, core_state: AppState<S>) -> Result<Self, error::WebError> {
let metadata_storage = Arc::new(SqliteStorage::new(storage_path).await?);
Ok(Self {
metadata_storage,
core_state,
})
}
}
pub fn create_router<
S: StorageClient
+ StorageSchemaContextOps
+ StorageSyncContextOps
+ StorageOperationContextOps
+ Clone
+ Send
+ Sync
+ 'static,
>(
web_state: WebState<S>,
) -> Router {
let queries_routes = handlers::metadata::create_routes();
let schema_routes = handlers::schema_ext::create_routes();
let data_routes = handlers::data_browser::create_routes();
let graph_routes = handlers::graph_data::create_routes();
Router::new()
.nest("/v1/queries", queries_routes)
.nest("/v1/schema", schema_routes)
.nest("/v1/data", data_routes)
.nest("/v1/graph", graph_routes)
.layer(axum_middleware::from_fn_with_state(
web_state.clone(),
middleware::web_auth_middleware,
))
.with_state(web_state)
}