| use axum::Json; | |
| use serde::Serialize; | |
| use crate::models::AppConfig; | |
| use crate::modules; | |
| use crate::error::AppError; | |
| /// API response wrapper | |
| pub struct ApiResponse<T> { | |
| pub success: bool, | |
| pub data: Option<T>, | |
| pub error: Option<String>, | |
| } | |
| impl<T: Serialize> ApiResponse<T> { | |
| pub fn success(data: T) -> Json<Self> { | |
| Json(Self { | |
| success: true, | |
| data: Some(data), | |
| error: None, | |
| }) | |
| } | |
| } | |
| /// Load configuration | |
| pub async fn load_config() -> Result<Json<ApiResponse<AppConfig>>, AppError> { | |
| let config = modules::load_app_config().map_err(AppError::Config)?; | |
| Ok(ApiResponse::success(config)) | |
| } | |
| /// Save configuration | |
| pub async fn save_config( | |
| Json(config): Json<AppConfig>, | |
| ) -> Result<Json<ApiResponse<()>>, AppError> { | |
| modules::save_app_config(&config).map_err(AppError::Config)?; | |
| modules::logger::log_info("Configuration saved"); | |
| Ok(ApiResponse::success(())) | |
| } | |