openlark_workflow/v2/comment/
update.rs1use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use crate::v2::comment::models::{UpdateCommentBody, UpdateCommentResponse};
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 UpdateCommentRequest {
17 config: Arc<Config>,
19 task_guid: String,
21 comment_guid: String,
23 body: UpdateCommentBody,
25}
26
27impl UpdateCommentRequest {
28 pub fn new(config: Arc<Config>, task_guid: String, comment_guid: String) -> Self {
29 Self {
30 config,
31 task_guid,
32 comment_guid,
33 body: UpdateCommentBody::default(),
34 }
35 }
36
37 pub fn content(mut self, content: impl Into<String>) -> Self {
39 self.body.content = content.into();
40 self
41 }
42
43 pub async fn execute(self) -> SDKResult<UpdateCommentResponse> {
45 self.execute_with_options(openlark_core::req_option::RequestOption::default())
46 .await
47 }
48
49 pub async fn execute_with_options(
51 self,
52 option: openlark_core::req_option::RequestOption,
53 ) -> SDKResult<UpdateCommentResponse> {
54 validate_required!(self.task_guid.trim(), "任务GUID不能为空");
56 validate_required!(self.comment_guid.trim(), "评论GUID不能为空");
57 validate_required!(self.body.content.trim(), "评论内容不能为空");
58
59 let api_endpoint =
60 TaskApiV2::CommentUpdate(self.task_guid.clone(), self.comment_guid.clone());
61 let mut request = ApiRequest::<UpdateCommentResponse>::put(api_endpoint.to_url());
62
63 let request_body = &self.body;
64 request = request.body(serialize_params(request_body, "更新评论")?);
65
66 let response =
67 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
68 extract_response_data(response, "更新评论")
69 }
70}
71
72impl ApiResponseTrait for UpdateCommentResponse {
73 fn data_format() -> ResponseFormat {
74 ResponseFormat::Data
75 }
76}
77
78#[cfg(test)]
79#[allow(unused_imports)]
80mod tests {
81 use std::sync::Arc;
82
83 use super::*;
84
85 #[test]
86 fn test_update_comment_builder() {
87 let config = Arc::new(
88 openlark_core::config::Config::builder()
89 .app_id("test")
90 .app_secret("test")
91 .build(),
92 );
93
94 let request =
95 UpdateCommentRequest::new(config, "task_123".to_string(), "comment_456".to_string())
96 .content("更新的评论内容");
97
98 assert_eq!(request.task_guid, "task_123");
99 assert_eq!(request.comment_guid, "comment_456");
100 assert_eq!(request.body.content, "更新的评论内容");
101 }
102}