botui/src/shared/state.rs

51 lines
1.4 KiB
Rust
Raw Normal View History

2025-12-03 18:42:22 -03:00
//! Application state management
//!
//! This module contains the shared application state that is passed to all
//! route handlers and provides access to database connections, configuration,
//! and other shared resources.
use std::sync::Arc;
use tokio::sync::RwLock;
/// Database connection pool type
/// This would typically be a real connection pool in production
pub type DbPool = Arc<RwLock<()>>;
/// Application state shared across all handlers
#[derive(Clone)]
pub struct AppState {
/// Database connection pool
pub conn: Arc<std::sync::Mutex<()>>,
/// Configuration cache
pub config: Arc<RwLock<std::collections::HashMap<String, String>>>,
/// Session store
pub sessions: Arc<RwLock<std::collections::HashMap<String, Session>>>,
}
/// User session information
#[derive(Clone, Debug)]
pub struct Session {
pub user_id: String,
pub username: String,
pub email: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub expires_at: chrono::DateTime<chrono::Utc>,
}
impl AppState {
/// Create a new application state
pub fn new() -> Self {
Self {
conn: Arc::new(std::sync::Mutex::new(())),
config: Arc::new(RwLock::new(std::collections::HashMap::new())),
sessions: Arc::new(RwLock::new(std::collections::HashMap::new())),
}
}
}
impl Default for AppState {
fn default() -> Self {
Self::new()
}
}