use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Default)]
pub struct CreateCommentBody {
pub content: String,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct UpdateCommentBody {
pub content: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct CreateCommentResponse {
pub comment_guid: String,
pub task_guid: String,
pub content: String,
pub creator: String,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetCommentResponse {
pub comment_guid: String,
pub task_guid: String,
pub content: String,
pub creator: String,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct UpdateCommentResponse {
pub comment_guid: String,
pub task_guid: String,
pub content: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DeleteCommentResponse {
pub success: bool,
pub comment_guid: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CommentItem {
pub comment_guid: String,
pub task_guid: String,
pub content: String,
pub creator: String,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ListCommentsResponse {
#[serde(default)]
pub has_more: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub page_token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub total: Option<i32>,
#[serde(default)]
pub items: Vec<CommentItem>,
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
assert_eq!(value["field"], "data");
}
}