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 comment_guid: String,
22 user_id_type: Option<String>,
24}
25
26impl GetCommentRequest {
27 pub fn new(config: Arc<Config>, comment_guid: String) -> Self {
29 Self {
30 config,
31 comment_guid,
32 user_id_type: None,
33 }
34 }
35
36 pub fn user_id_type(mut self, user_id_type: impl Into<String>) -> Self {
38 self.user_id_type = Some(user_id_type.into());
39 self
40 }
41
42 pub async fn execute(self) -> SDKResult<GetCommentResponse> {
44 self.execute_with_options(openlark_core::req_option::RequestOption::default())
45 .await
46 }
47
48 pub async fn execute_with_options(
50 self,
51 option: openlark_core::req_option::RequestOption,
52 ) -> SDKResult<GetCommentResponse> {
53 validate_required!(self.comment_guid.trim(), "评论GUID不能为空");
55
56 let api_endpoint = TaskApiV2::CommentGet(self.comment_guid.clone());
57 let mut request = ApiRequest::<GetCommentResponse>::get(api_endpoint.to_url());
58 if let Some(user_id_type) = &self.user_id_type {
59 request = request.query("user_id_type", user_id_type);
60 }
61
62 let response =
63 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
64 extract_response_data(response, "获取评论")
65 }
66}
67
68impl ApiResponseTrait for GetCommentResponse {
69 fn data_format() -> ResponseFormat {
70 ResponseFormat::Data
71 }
72}
73
74#[cfg(test)]
75#[allow(unused_imports)]
76mod tests {
77 use std::sync::Arc;
78
79 use super::*;
80
81 #[test]
82 fn test_get_comment_request() {
83 let config = openlark_core::config::Config::builder()
84 .app_id("test")
85 .app_secret("test")
86 .build();
87
88 let request = GetCommentRequest::new(Arc::new(config), "comment_456".to_string());
89
90 assert_eq!(request.comment_guid, "comment_456");
91 }
92}