use serde::{Deserialize, Serialize};
use utoipa::IntoParams;
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
pub struct TriggerJobResponse {
pub execution_id: String,
pub message: String,
}
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
pub struct JobExecutionResponse {
pub id: String,
pub job_name: String,
pub status: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub started_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub exit_code: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub logs: Option<String>,
pub trigger: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration_ms: Option<u64>,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct ListExecutionsQuery {
#[serde(default = "default_limit")]
pub limit: usize,
#[serde(default)]
pub status: Option<String>,
}
fn default_limit() -> usize {
50
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_trigger_response_serialize() {
let response = TriggerJobResponse {
execution_id: "abc-123".to_string(),
message: "Job triggered".to_string(),
};
let json = serde_json::to_string(&response).unwrap();
assert!(json.contains("abc-123"));
assert!(json.contains("Job triggered"));
}
#[test]
fn test_execution_response_serialize() {
let response = JobExecutionResponse {
id: "exec-123".to_string(),
job_name: "backup".to_string(),
status: "completed".to_string(),
started_at: Some("2025-01-25T12:00:00Z".to_string()),
completed_at: Some("2025-01-25T12:01:00Z".to_string()),
exit_code: Some(0),
logs: Some("Done!".to_string()),
trigger: "cli".to_string(),
error: None,
duration_ms: Some(5000),
};
let json = serde_json::to_string(&response).unwrap();
assert!(json.contains("exec-123"));
assert!(json.contains("backup"));
assert!(json.contains("completed"));
}
#[test]
fn test_list_query_defaults() {
let query: ListExecutionsQuery = serde_json::from_str("{}").unwrap();
assert_eq!(query.limit, 50);
assert!(query.status.is_none());
}
}