refactor: drop unused code
This commit is contained in:
@@ -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
|
// Log handlers
|
||||||
pub async fn list_logs(
|
pub async fn list_logs(
|
||||||
State(state): State<Arc<AppContext>>,
|
State(state): State<Arc<AppContext>>,
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ pub fn admin_routes(ctx: Arc<AppContext>) -> Router<Arc<AppContext>> {
|
|||||||
.route("/api/rules/{:id}", delete(handlers::delete_rule))
|
.route("/api/rules/{:id}", delete(handlers::delete_rule))
|
||||||
.route("/api/commands", get(handlers::list_commands))
|
.route("/api/commands", get(handlers::list_commands))
|
||||||
.route("/api/commands/{:id}", post(handlers::verify_command))
|
.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))
|
.route("/api/logs", get(handlers::list_logs))
|
||||||
.layer(axum::middleware::from_fn_with_state(
|
.layer(axum::middleware::from_fn_with_state(
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
@@ -57,18 +57,6 @@ pub async fn update_status(
|
|||||||
Ok(())
|
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<()> {
|
pub async fn clear_verified(pool: &SqlitePool) -> anyhow::Result<()> {
|
||||||
sqlx::query("DELETE FROM commands WHERE status = 'verified'")
|
sqlx::query("DELETE FROM commands WHERE status = 'verified'")
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
use crate::db::models::Config;
|
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
pub async fn get_all(pool: &SqlitePool) -> anyhow::Result<HashMap<String, String>> {
|
use crate::db::models::Config;
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get(pool: &SqlitePool, key: &str) -> anyhow::Result<Option<String>> {
|
pub async fn get(pool: &SqlitePool, key: &str) -> anyhow::Result<Option<String>> {
|
||||||
let config = sqlx::query_as::<_, Config>("SELECT * FROM config WHERE key = ?")
|
let config = sqlx::query_as::<_, Config>("SELECT * FROM config WHERE key = ?")
|
||||||
@@ -40,12 +30,3 @@ pub async fn set(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(pool: &SqlitePool, key: &str) -> anyhow::Result<()> {
|
|
||||||
sqlx::query("DELETE FROM config WHERE key = ?")
|
|
||||||
.bind(key)
|
|
||||||
.execute(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user