open_lark/service/contact/v3/
custom_attr.rs

1use crate::{
2    core::{
3        api_req::ApiRequest, api_resp::ApiResponseTrait, config::Config,
4        constants::AccessTokenType, http::Transport,
5    },
6    service::contact::models::*,
7};
8use serde::{Deserialize, Serialize};
9
10/// 自定义用户字段服务
11pub struct CustomAttrService {
12    config: Config,
13}
14
15impl CustomAttrService {
16    pub fn new(config: Config) -> Self {
17        Self { config }
18    }
19
20    /// 获取企业自定义用户字段
21    pub async fn list(
22        &self,
23        _req: &ListCustomAttrsRequest,
24    ) -> crate::core::SDKResult<ListCustomAttrsResponse> {
25        let api_req = ApiRequest {
26            http_method: reqwest::Method::GET,
27            api_path: crate::core::endpoints::contact::CONTACT_V3_CUSTOM_ATTRS.to_string(),
28            supported_access_token_types: vec![AccessTokenType::Tenant],
29            body: Vec::new(),
30            query_params: std::collections::HashMap::new(),
31            ..Default::default()
32        };
33
34        let resp =
35            Transport::<ListCustomAttrsResponse>::request(api_req, &self.config, None).await?;
36        Ok(resp.data.unwrap_or_default())
37    }
38}
39
40#[derive(Debug, Clone, Default, Serialize, Deserialize)]
41pub struct ListCustomAttrsRequest {
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub page_size: Option<i32>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub page_token: Option<String>,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, Default)]
49pub struct ListCustomAttrsResponse {
50    pub items: Vec<CustomAttr>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub has_more: Option<bool>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub page_token: Option<String>,
55}
56
57impl ApiResponseTrait for ListCustomAttrsResponse {
58    fn data_format() -> crate::core::api_resp::ResponseFormat {
59        crate::core::api_resp::ResponseFormat::Data
60    }
61}