Skip to main content

openlark_workflow/v2/custom_field/
models.rs

1//! 自定义字段 API v2 的数据模型
2
3use serde::{Deserialize, Serialize};
4
5/// 自定义字段类型
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(rename_all = "snake_case")]
8pub enum CustomFieldType {
9    /// 文本
10    Text,
11    /// 数字
12    Number,
13    /// 日期
14    Date,
15    /// 人员
16    Person,
17    /// 复选框
18    Checkbox,
19    /// 下拉选项
20    Select,
21}
22
23/// 自定义字段配置
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
25pub struct CustomFieldConfig {
26    /// 字段类型
27    #[serde(rename = "type")]
28    pub field_type: CustomFieldType,
29    /// 字段选项(用于 Select 类型)
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub options: Option<Vec<String>>,
32}
33
34impl Default for CustomFieldConfig {
35    fn default() -> Self {
36        Self {
37            field_type: CustomFieldType::Text,
38            options: None,
39        }
40    }
41}
42
43/// 创建自定义字段请求体
44#[derive(Debug, Clone, Serialize, Default)]
45pub struct CreateCustomFieldBody {
46    /// 字段名称
47    pub name: String,
48    /// 字段配置
49    pub config: CustomFieldConfig,
50    /// 资源类型(目前官方仅支持 "tasklist")
51    pub resource_type: String,
52    /// 资源 GUID(挂载的清单 GUID)
53    pub resource_id: String,
54}
55
56/// 更新自定义字段请求体
57#[derive(Debug, Clone, Serialize, Default)]
58pub struct UpdateCustomFieldBody {
59    /// 字段名称
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub name: Option<String>,
62    /// 字段配置
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub config: Option<CustomFieldConfig>,
65}
66
67/// 创建自定义字段响应
68#[derive(Debug, Clone, Deserialize)]
69pub struct CreateCustomFieldResponse {
70    /// 字段 GUID
71    pub field_guid: String,
72    /// 字段名称
73    pub name: String,
74    /// 字段配置
75    pub config: CustomFieldConfig,
76    /// 创建时间
77    pub created_at: String,
78    /// 更新时间
79    pub updated_at: String,
80}
81
82/// 获取自定义字段响应
83#[derive(Debug, Clone, Deserialize)]
84pub struct GetCustomFieldResponse {
85    /// 字段 GUID
86    pub field_guid: String,
87    /// 字段名称
88    pub name: String,
89    /// 字段配置
90    pub config: CustomFieldConfig,
91    /// 创建时间
92    pub created_at: String,
93    /// 更新时间
94    pub updated_at: String,
95}
96
97/// 更新自定义字段响应
98#[derive(Debug, Clone, Deserialize)]
99pub struct UpdateCustomFieldResponse {
100    /// 字段 GUID
101    pub field_guid: String,
102    /// 字段名称
103    pub name: String,
104    /// 字段配置
105    pub config: CustomFieldConfig,
106    /// 更新时间
107    pub updated_at: String,
108}
109
110/// 删除自定义字段响应
111#[derive(Debug, Clone, Deserialize)]
112pub struct DeleteCustomFieldResponse {
113    /// 是否删除成功
114    pub success: bool,
115    /// 字段 GUID
116    pub field_guid: String,
117}
118
119/// 自定义字段列表项
120#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
121pub struct CustomFieldItem {
122    /// 字段 GUID
123    pub field_guid: String,
124    /// 字段名称
125    pub name: String,
126    /// 字段配置
127    pub config: CustomFieldConfig,
128    /// 创建时间
129    pub created_at: String,
130    /// 更新时间
131    pub updated_at: String,
132}
133
134/// 获取自定义字段列表响应
135#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
136pub struct ListCustomFieldsResponse {
137    /// 是否还有更多项
138    #[serde(default)]
139    pub has_more: bool,
140    /// 分页标记
141    #[serde(skip_serializing_if = "Option::is_none")]
142    pub page_token: Option<String>,
143    /// 总数
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub total: Option<i32>,
146    /// 列表项
147    #[serde(default)]
148    pub items: Vec<CustomFieldItem>,
149}