Files
vibe-kanban/backend/src/routes/config.rs
Louis Knight-Webb 57e31ea623 Squashed commit of the following:
commit f29ca62b42df9ac7ff2dafd5132c3e12a1a6a3e7
Author: Louis Knight-Webb <louis@bloop.ai>
Date:   Thu Jun 19 12:52:48 2025 -0400

    Settings

commit 1215b493bbabeac9f446dd2996cb6275df069770
Author: Louis Knight-Webb <louis@bloop.ai>
Date:   Thu Jun 19 12:44:36 2025 -0400

    Consolidate types

commit d0960d989d24d6068728056d28820415c6cdea2c
Author: Louis Knight-Webb <louis@bloop.ai>
Date:   Thu Jun 19 12:32:15 2025 -0400

    Partial
2025-06-19 12:53:41 -04:00

54 lines
1.4 KiB
Rust

use axum::{
extract::Extension,
response::Json as ResponseJson,
routing::{get, post},
Json, Router,
};
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::models::{config::Config, ApiResponse};
use crate::utils;
pub fn config_router() -> Router {
Router::new()
.route("/config", get(get_config))
.route("/config", post(update_config))
}
async fn get_config(
Extension(config): Extension<Arc<RwLock<Config>>>,
) -> ResponseJson<ApiResponse<Config>> {
let config = config.read().await;
ResponseJson(ApiResponse {
success: true,
data: Some(config.clone()),
message: Some("Config retrieved successfully".to_string()),
})
}
async fn update_config(
Extension(config_arc): Extension<Arc<RwLock<Config>>>,
Json(new_config): Json<Config>,
) -> ResponseJson<ApiResponse<Config>> {
let config_path = utils::config_path();
match new_config.save(&config_path) {
Ok(_) => {
let mut config = config_arc.write().await;
*config = new_config.clone();
ResponseJson(ApiResponse {
success: true,
data: Some(new_config),
message: Some("Config updated successfully".to_string()),
})
}
Err(e) => ResponseJson(ApiResponse {
success: false,
data: None,
message: Some(format!("Failed to save config: {}", e)),
}),
}
}