use axum::response::Json;
use serde::Deserialize;
use crate::ai::{ValidationConfig, ValidationPipeline, ValidationResult};
use crate::error::DbError;
#[derive(Debug, Deserialize)]
pub struct RunValidationRequest {
#[serde(default)]
pub project_root: Option<String>,
#[serde(default = "default_true")]
pub run_tests: bool,
#[serde(default = "default_true")]
pub run_clippy: bool,
#[serde(default = "default_true")]
pub run_rustfmt: bool,
#[serde(default)]
pub quick: bool,
}
fn default_true() -> bool {
true
}
pub async fn run_validation_handler(
Json(request): Json<RunValidationRequest>,
) -> Result<Json<ValidationResult>, DbError> {
let project_root = request.project_root.unwrap_or_else(|| ".".to_string());
if !crate::ai::validation::path_exists(&project_root) {
return Err(DbError::BadRequest(format!(
"Project root does not exist: {}",
project_root
)));
}
let config = ValidationConfig {
project_root,
run_tests: request.run_tests && !request.quick,
run_clippy: request.run_clippy,
run_rustfmt: request.run_rustfmt,
test_timeout_secs: 300,
test_filter: None,
};
let pipeline = ValidationPipeline::new(config);
let result = if request.quick {
pipeline.run_quick()
} else {
pipeline.run()
};
Ok(Json(result))
}
pub async fn run_quick_validation_handler() -> Result<Json<ValidationResult>, DbError> {
let pipeline = ValidationPipeline::for_project(".");
let result = pipeline.run_quick();
Ok(Json(result))
}