use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] pub struct Task { pub id: String, pub title: String, pub description: Option, pub completed: bool, pub created_at: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GraphNode { pub id: String, pub label: String, pub completed: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GraphEdge { pub source: String, pub target: String, pub weight: f32, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GraphData { pub nodes: Vec, pub edges: Vec, } #[derive(Debug, Deserialize)] pub struct CreateTask { pub title: String, pub description: Option, } #[derive(Debug, Deserialize)] pub struct UpdateTask { pub title: Option, pub description: Option, pub completed: Option, } #[cfg(test)] mod tests { use super::*; #[test] fn test_task_serialization() { let task = Task { id: "abc-123".to_string(), title: "Test task".to_string(), description: Some("A description".to_string()), completed: false, created_at: 1234567890, }; let json = serde_json::to_string(&task).unwrap(); let deserialized: Task = serde_json::from_str(&json).unwrap(); assert_eq!(deserialized.id, task.id); assert_eq!(deserialized.title, task.title); assert_eq!(deserialized.completed, task.completed); } #[test] fn test_task_no_description() { let task = Task { id: "xyz".to_string(), title: "No desc".to_string(), description: None, completed: true, created_at: 0, }; let json = serde_json::to_string(&task).unwrap(); assert!(json.contains("\"description\":null")); } }