Skip to main content

openlark_workflow/v2/comment/
models.rs

1//! 评论 API v2 的数据模型
2
3use serde::{Deserialize, Serialize};
4
5/// 创建评论请求体
6#[derive(Debug, Clone, Serialize, Default)]
7pub struct CreateCommentBody {
8    /// 评论内容
9    pub content: String,
10}
11
12/// 更新评论请求体
13#[derive(Debug, Clone, Serialize, Default)]
14pub struct UpdateCommentBody {
15    /// 评论内容
16    pub content: String,
17}
18
19/// 创建评论响应
20#[derive(Debug, Clone, Deserialize)]
21pub struct CreateCommentResponse {
22    /// 评论 GUID
23    pub comment_guid: String,
24    /// 任务 GUID
25    pub task_guid: String,
26    /// 评论内容
27    pub content: String,
28    /// 评论创建者
29    pub creator: String,
30    /// 创建时间
31    pub created_at: String,
32    /// 更新时间
33    pub updated_at: String,
34}
35
36/// 获取评论响应
37#[derive(Debug, Clone, Deserialize)]
38pub struct GetCommentResponse {
39    /// 评论 GUID
40    pub comment_guid: String,
41    /// 任务 GUID
42    pub task_guid: String,
43    /// 评论内容
44    pub content: String,
45    /// 评论创建者
46    pub creator: String,
47    /// 创建时间
48    pub created_at: String,
49    /// 更新时间
50    pub updated_at: String,
51}
52
53/// 更新评论响应
54#[derive(Debug, Clone, Deserialize)]
55pub struct UpdateCommentResponse {
56    /// 评论 GUID
57    pub comment_guid: String,
58    /// 任务 GUID
59    pub task_guid: String,
60    /// 评论内容
61    pub content: String,
62    /// 更新时间
63    pub updated_at: String,
64}
65
66/// 删除评论响应
67#[derive(Debug, Clone, Deserialize)]
68pub struct DeleteCommentResponse {
69    /// 是否删除成功
70    pub success: bool,
71    /// 评论 GUID
72    pub comment_guid: String,
73}
74
75/// 评论列表项
76#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
77pub struct CommentItem {
78    /// 评论 GUID
79    pub comment_guid: String,
80    /// 任务 GUID
81    pub task_guid: String,
82    /// 评论内容
83    pub content: String,
84    /// 评论创建者
85    pub creator: String,
86    /// 创建时间
87    pub created_at: String,
88    /// 更新时间
89    pub updated_at: String,
90}
91
92/// 获取评论列表响应
93#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
94pub struct ListCommentsResponse {
95    /// 是否还有更多项
96    #[serde(default)]
97    pub has_more: bool,
98    /// 分页标记
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub page_token: Option<String>,
101    /// 总数
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub total: Option<i32>,
104    /// 列表项
105    #[serde(default)]
106    pub items: Vec<CommentItem>,
107}
108
109#[cfg(test)]
110#[allow(unused_imports)]
111mod tests {
112
113    #[test]
114    fn test_serialization_roundtrip() {
115        // 基础序列化测试
116        let json = r#"{"test": "value"}"#;
117        assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
118    }
119
120    #[test]
121    fn test_deserialization_from_json() {
122        // 基础反序列化测试
123        let json = r#"{"field": "data"}"#;
124        let value: serde_json::Value = serde_json::from_str(json).unwrap();
125        assert_eq!(value["field"], "data");
126    }
127}