refactor: drop unused code

This commit is contained in:
2025-12-06 13:36:17 +08:00
parent 66a2245733
commit 55dd5f3722
4 changed files with 1 additions and 68 deletions

View File

@@ -310,40 +310,6 @@ pub async fn verify_command(
}
}
}
// Config handlers
pub async fn get_config(
State(state): State<Arc<AppContext>>,
) -> Result<Json<std::collections::HashMap<String, String>>, (StatusCode, Json<ApiError>)> {
match db::repositories::config::get_all(&state.db).await {
Ok(config) => Ok(Json(config)),
Err(e) => {
error!("Failed to get config: {}", e);
Err((
StatusCode::INTERNAL_SERVER_ERROR,
Json(ApiError::new("Failed to fetch configuration")),
))
}
}
}
pub async fn update_config(
State(state): State<Arc<AppContext>>,
Json(config): Json<std::collections::HashMap<String, String>>,
) -> Result<StatusCode, (StatusCode, Json<ApiError>)> {
for (key, value) in config {
if let Err(e) = db::repositories::config::set(&state.db, &key, &value, None).await {
error!("Failed to update config {}: {}", key, e);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
Json(ApiError::new(format!("Failed to update config: {}", e))),
));
}
}
Ok(StatusCode::OK)
}
// Log handlers
pub async fn list_logs(
State(state): State<Arc<AppContext>>,

View File

@@ -22,8 +22,6 @@ pub fn admin_routes(ctx: Arc<AppContext>) -> Router<Arc<AppContext>> {
.route("/api/rules/{:id}", delete(handlers::delete_rule))
.route("/api/commands", get(handlers::list_commands))
.route("/api/commands/{:id}", post(handlers::verify_command))
.route("/api/config", get(handlers::get_config))
.route("/api/config", put(handlers::update_config))
.route("/api/logs", get(handlers::list_logs))
.layer(axum::middleware::from_fn_with_state(
ctx,

View File

@@ -57,18 +57,6 @@ pub async fn update_status(
Ok(())
}
pub async fn delete_old(pool: &SqlitePool, days: i64) -> anyhow::Result<u64> {
let result = sqlx::query(
"DELETE FROM commands WHERE status IN ('verified', 'rejected')
AND processed_at < datetime('now', '-' || ? || ' days')",
)
.bind(days)
.execute(pool)
.await?;
Ok(result.rows_affected())
}
pub async fn clear_verified(pool: &SqlitePool) -> anyhow::Result<()> {
sqlx::query("DELETE FROM commands WHERE status = 'verified'")
.execute(pool)

View File

@@ -1,16 +1,6 @@
use crate::db::models::Config;
use sqlx::SqlitePool;
use std::collections::HashMap;
pub async fn get_all(pool: &SqlitePool) -> anyhow::Result<HashMap<String, String>> {
let configs = sqlx::query_as::<_, Config>("SELECT * FROM config")
.fetch_all(pool)
.await?;
let map: HashMap<String, String> = configs.into_iter().map(|c| (c.key, c.value)).collect();
Ok(map)
}
use crate::db::models::Config;
pub async fn get(pool: &SqlitePool, key: &str) -> anyhow::Result<Option<String>> {
let config = sqlx::query_as::<_, Config>("SELECT * FROM config WHERE key = ?")
@@ -40,12 +30,3 @@ pub async fn set(
Ok(())
}
pub async fn delete(pool: &SqlitePool, key: &str) -> anyhow::Result<()> {
sqlx::query("DELETE FROM config WHERE key = ?")
.bind(key)
.execute(pool)
.await?;
Ok(())
}