openlark_workflow/v1/task/comment/
get.rs1use openlark_core::{
6 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
7 config::Config,
8 SDKResult,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Deserialize)]
15pub struct GetTaskCommentResponseV1 {
16 pub comment_id: String,
18 pub content: String,
20 pub creator_id: String,
22 pub created_at: Option<String>,
24 pub parent_id: Option<String>,
26}
27
28#[derive(Debug, Clone)]
30pub struct GetTaskCommentRequestV1 {
31 config: Arc<Config>,
32 task_id: String,
33 comment_id: String,
34}
35
36impl GetTaskCommentRequestV1 {
37 pub fn new(
38 config: Arc<Config>,
39 task_id: impl Into<String>,
40 comment_id: impl Into<String>,
41 ) -> Self {
42 Self {
43 config,
44 task_id: task_id.into(),
45 comment_id: comment_id.into(),
46 }
47 }
48
49 pub async fn execute(self) -> SDKResult<GetTaskCommentResponseV1> {
51 self.execute_with_options(openlark_core::req_option::RequestOption::default())
52 .await
53 }
54
55 pub async fn execute_with_options(
57 self,
58 option: openlark_core::req_option::RequestOption,
59 ) -> SDKResult<GetTaskCommentResponseV1> {
60 let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
61 self.task_id.clone(),
62 self.comment_id.clone(),
63 );
64 let request = ApiRequest::<GetTaskCommentResponseV1>::get(api_endpoint.to_url());
65
66 let response =
67 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
68 response.data.ok_or_else(|| {
69 openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
70 })
71 }
72}
73
74impl ApiResponseTrait for GetTaskCommentResponseV1 {
75 fn data_format() -> ResponseFormat {
76 ResponseFormat::Data
77 }
78}
79
80#[cfg(test)]
81#[allow(unused_imports)]
82mod tests {
83
84 #[test]
85 fn test_get_task_comment_v1_url() {
86 let endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
87 "task_123".to_string(),
88 "comment_456".to_string(),
89 );
90 assert_eq!(
91 endpoint.to_url(),
92 "/open-apis/task/v1/tasks/task_123/comments/comment_456"
93 );
94 }
95}