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