openlark_workflow/v2/comment/
get.rs1use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use crate::v2::comment::models::GetCommentResponse;
7use openlark_core::{
8 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
9 config::Config,
10 validate_required, SDKResult,
11};
12use std::sync::Arc;
13
14#[derive(Debug, Clone)]
16pub struct GetCommentRequest {
17 config: Arc<Config>,
19 task_guid: String,
21 comment_guid: String,
23}
24
25impl GetCommentRequest {
26 pub fn new(config: Arc<Config>, task_guid: String, comment_guid: String) -> Self {
27 Self {
28 config,
29 task_guid,
30 comment_guid,
31 }
32 }
33
34 pub async fn execute(self) -> SDKResult<GetCommentResponse> {
36 self.execute_with_options(openlark_core::req_option::RequestOption::default())
37 .await
38 }
39
40 pub async fn execute_with_options(
42 self,
43 option: openlark_core::req_option::RequestOption,
44 ) -> SDKResult<GetCommentResponse> {
45 validate_required!(self.task_guid.trim(), "任务GUID不能为空");
47 validate_required!(self.comment_guid.trim(), "评论GUID不能为空");
48
49 let api_endpoint = TaskApiV2::CommentGet(self.task_guid.clone(), self.comment_guid.clone());
50 let request = ApiRequest::<GetCommentResponse>::get(api_endpoint.to_url());
51
52 let response =
53 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
54 extract_response_data(response, "获取评论")
55 }
56}
57
58impl ApiResponseTrait for GetCommentResponse {
59 fn data_format() -> ResponseFormat {
60 ResponseFormat::Data
61 }
62}
63
64#[cfg(test)]
65#[allow(unused_imports)]
66mod tests {
67 use std::sync::Arc;
68
69 use super::*;
70
71 #[test]
72 fn test_get_comment_request() {
73 let config = openlark_core::config::Config::builder()
74 .app_id("test")
75 .app_secret("test")
76 .build();
77
78 let request = GetCommentRequest::new(
79 Arc::new(config),
80 "task_123".to_string(),
81 "comment_456".to_string(),
82 );
83
84 assert_eq!(request.task_guid, "task_123");
85 assert_eq!(request.comment_guid, "comment_456");
86 }
87}