Skip to main content

openlark_workflow/v2/section/
models.rs

1//! 分组 API v2 的数据模型
2
3use serde::{Deserialize, Serialize};
4
5/// 创建分组请求体
6#[derive(Debug, Clone, Serialize, Default)]
7pub struct CreateSectionBody {
8    /// 分组标题
9    pub summary: String,
10
11    /// 分组描述
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub description: Option<String>,
14}
15
16/// 更新分组请求体
17#[derive(Debug, Clone, Serialize, Default)]
18pub struct UpdateSectionBody {
19    /// 分组标题
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub summary: Option<String>,
22
23    /// 分组描述
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub description: Option<String>,
26}
27
28/// 创建分组响应
29#[derive(Debug, Clone, Deserialize)]
30pub struct CreateSectionResponse {
31    /// 分组 GUID
32    pub section_guid: String,
33
34    /// 分组标题
35    pub summary: String,
36
37    /// 分组描述
38    #[serde(default)]
39    pub description: Option<String>,
40
41    /// 创建时间
42    pub created_at: String,
43
44    /// 更新时间
45    pub updated_at: String,
46}
47
48/// 获取分组响应
49#[derive(Debug, Clone, Deserialize)]
50pub struct GetSectionResponse {
51    /// 分组 GUID
52    pub section_guid: String,
53
54    /// 分组标题
55    pub summary: String,
56
57    /// 分组描述
58    #[serde(default)]
59    pub description: Option<String>,
60
61    /// 创建时间
62    pub created_at: String,
63
64    /// 更新时间
65    pub updated_at: String,
66}
67
68/// 更新分组响应
69#[derive(Debug, Clone, Deserialize)]
70pub struct UpdateSectionResponse {
71    /// 分组 GUID
72    pub section_guid: String,
73
74    /// 分组标题
75    pub summary: String,
76
77    /// 分组描述
78    #[serde(default)]
79    pub description: Option<String>,
80
81    /// 更新时间
82    pub updated_at: String,
83}
84
85/// 删除分组响应
86#[derive(Debug, Clone, Deserialize)]
87pub struct DeleteSectionResponse {
88    /// 是否删除成功
89    pub success: bool,
90
91    /// 分组 GUID
92    pub section_guid: String,
93}
94
95/// 分组列表项
96#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
97pub struct SectionItem {
98    /// 分组 GUID
99    pub section_guid: String,
100
101    /// 分组标题
102    pub summary: String,
103
104    /// 分组描述
105    #[serde(default)]
106    pub description: Option<String>,
107
108    /// 创建时间
109    pub created_at: String,
110
111    /// 更新时间
112    pub updated_at: String,
113}
114
115/// 获取分组列表响应
116#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
117pub struct ListSectionsResponse {
118    /// 是否还有更多项
119    #[serde(default)]
120    pub has_more: bool,
121
122    /// 分页标记
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub page_token: Option<String>,
125
126    /// 总数
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub total: Option<i32>,
129
130    /// 列表项
131    #[serde(default)]
132    pub items: Vec<SectionItem>,
133}
134
135#[cfg(test)]
136#[allow(unused_imports)]
137mod tests {
138
139    #[test]
140    fn test_serialization_roundtrip() {
141        // 基础序列化测试
142        let json = r#"{"test": "value"}"#;
143        assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
144    }
145
146    #[test]
147    fn test_deserialization_from_json() {
148        // 基础反序列化测试
149        let json = r#"{"field": "data"}"#;
150        let value: serde_json::Value = serde_json::from_str(json).unwrap();
151        assert_eq!(value["field"], "data");
152    }
153}