openlark_workflow/v1/task/comment/
get.rs1use openlark_core::{
6 SDKResult,
7 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8 config::Config,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Deserialize)]
15pub struct GetTaskCommentResponseV1 {
17 pub comment_id: String,
19 pub content: String,
21 pub creator_id: String,
23 pub created_at: Option<String>,
25 pub parent_id: Option<String>,
27}
28
29#[derive(Debug, Clone)]
31pub struct GetTaskCommentRequestV1 {
33 config: Arc<Config>,
34 task_id: String,
35 comment_id: String,
36}
37
38impl GetTaskCommentRequestV1 {
39 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 pub async fn execute(self) -> SDKResult<GetTaskCommentResponseV1> {
54 self.execute_with_options(openlark_core::req_option::RequestOption::default())
55 .await
56 }
57
58 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}