Skip to main content

openlark_workflow/v1/task/comment/
get.rs

1//! 获取任务评论详情(v1)
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v1/taskcomment/get
4
5use openlark_core::{
6    SDKResult,
7    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8    config::Config,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13/// 任务评论详情(v1)
14#[derive(Debug, Clone, Deserialize)]
15/// 任务评论详情响应。
16pub struct GetTaskCommentResponseV1 {
17    /// 评论 ID
18    pub comment_id: String,
19    /// 评论内容
20    pub content: String,
21    /// 创建者用户 ID
22    pub creator_id: String,
23    /// 创建时间
24    pub created_at: Option<String>,
25    /// 父评论 ID
26    pub parent_id: Option<String>,
27}
28
29/// 获取任务评论详情请求(v1)
30#[derive(Debug, Clone)]
31/// 获取任务评论详情请求构建器。
32pub struct GetTaskCommentRequestV1 {
33    config: Arc<Config>,
34    task_id: String,
35    comment_id: String,
36}
37
38impl GetTaskCommentRequestV1 {
39    /// 创建新的请求构建器。
40    pub fn new(
41        config: Arc<Config>,
42        task_id: impl Into<String>,
43        comment_id: impl Into<String>,
44    ) -> Self {
45        Self {
46            config,
47            task_id: task_id.into(),
48            comment_id: comment_id.into(),
49        }
50    }
51
52    /// 执行请求
53    pub async fn execute(self) -> SDKResult<GetTaskCommentResponseV1> {
54        self.execute_with_options(openlark_core::req_option::RequestOption::default())
55            .await
56    }
57
58    /// 执行请求(带选项)
59    pub async fn execute_with_options(
60        self,
61        option: openlark_core::req_option::RequestOption,
62    ) -> SDKResult<GetTaskCommentResponseV1> {
63        let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
64            self.task_id.clone(),
65            self.comment_id.clone(),
66        );
67        let request = ApiRequest::<GetTaskCommentResponseV1>::get(api_endpoint.to_url());
68
69        let response =
70            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
71        response.data.ok_or_else(|| {
72            openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
73        })
74    }
75}
76
77impl ApiResponseTrait for GetTaskCommentResponseV1 {
78    fn data_format() -> ResponseFormat {
79        ResponseFormat::Data
80    }
81}
82
83#[cfg(test)]
84#[allow(unused_imports)]
85mod tests {
86
87    #[test]
88    fn test_get_task_comment_v1_url() {
89        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
90            "task_123".to_string(),
91            "comment_456".to_string(),
92        );
93        assert_eq!(
94            endpoint.to_url(),
95            "/open-apis/task/v1/tasks/task_123/comments/comment_456"
96        );
97    }
98}