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        openlark_core::http::Transport::request_typed(
70            request,
71            &self.config,
72            Some(option),
73            "响应数据为空",
74        )
75        .await
76    }
77}
78
79impl ApiResponseTrait for GetTaskCommentResponseV1 {
80    fn data_format() -> ResponseFormat {
81        ResponseFormat::Data
82    }
83}
84
85#[cfg(test)]
86#[allow(unused_imports)]
87mod tests {
88
89    #[test]
90    fn test_get_task_comment_v1_url() {
91        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
92            "task_123".to_string(),
93            "comment_456".to_string(),
94        );
95        assert_eq!(
96            endpoint.to_url(),
97            "/open-apis/task/v1/tasks/task_123/comments/comment_456"
98        );
99    }
100}