Skip to main content

openlark_workflow/v2/comment/
get.rs

1//! 获取评论详情
2//!
3//! docPath: <https://open.feishu.cn/document/task-v2/comment/get>
4
5use crate::common::api_endpoints::TaskApiV2;
6use crate::v2::comment::models::GetCommentResponse;
7use openlark_core::{
8    SDKResult,
9    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
10    config::Config,
11    validate_required,
12};
13use std::sync::Arc;
14
15/// 获取评论请求
16#[derive(Debug, Clone)]
17pub struct GetCommentRequest {
18    /// 配置信息
19    config: Arc<Config>,
20    /// 评论 GUID
21    comment_guid: String,
22    /// 用户 ID 类型
23    user_id_type: Option<String>,
24}
25
26impl GetCommentRequest {
27    /// 创建新的请求构建器。
28    pub fn new(config: Arc<Config>, comment_guid: String) -> Self {
29        Self {
30            config,
31            comment_guid,
32            user_id_type: None,
33        }
34    }
35
36    /// 设置用户 ID 类型。
37    pub fn user_id_type(mut self, user_id_type: impl Into<String>) -> Self {
38        self.user_id_type = Some(user_id_type.into());
39        self
40    }
41
42    /// 执行请求
43    pub async fn execute(self) -> SDKResult<GetCommentResponse> {
44        self.execute_with_options(openlark_core::req_option::RequestOption::default())
45            .await
46    }
47
48    /// 执行请求(带选项)
49    pub async fn execute_with_options(
50        self,
51        option: openlark_core::req_option::RequestOption,
52    ) -> SDKResult<GetCommentResponse> {
53        // 验证必填字段
54        validate_required!(self.comment_guid.trim(), "评论GUID不能为空");
55
56        let api_endpoint = TaskApiV2::CommentGet(self.comment_guid.clone());
57        let mut request = ApiRequest::<GetCommentResponse>::get(api_endpoint.to_url());
58        if let Some(user_id_type) = &self.user_id_type {
59            request = request.query("user_id_type", user_id_type);
60        }
61
62        openlark_core::http::Transport::request_typed(
63            request,
64            &self.config,
65            Some(option),
66            "获取评论",
67        )
68        .await
69    }
70}
71
72impl ApiResponseTrait for GetCommentResponse {
73    fn data_format() -> ResponseFormat {
74        ResponseFormat::Data
75    }
76}
77
78#[cfg(test)]
79#[allow(unused_imports)]
80mod tests {
81    use std::sync::Arc;
82
83    use super::*;
84
85    #[test]
86    fn test_get_comment_request() {
87        let config = openlark_core::config::Config::builder()
88            .app_id("test")
89            .app_secret("test")
90            .build();
91
92        let request = GetCommentRequest::new(Arc::new(config), "comment_456".to_string());
93
94        assert_eq!(request.comment_guid, "comment_456");
95    }
96}