Skip to main content

openlark_workflow/v2/comment/
delete.rs

1//! 删除评论
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v2/comment/delete
4
5use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use crate::v2::comment::models::DeleteCommentResponse;
7use openlark_core::{
8    SDKResult,
9    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
10    config::Config,
11    validate_required,
12};
13use std::sync::Arc;
14
15/// 删除评论请求
16#[derive(Debug, Clone)]
17pub struct DeleteCommentRequest {
18    /// 配置信息
19    config: Arc<Config>,
20    /// 任务 GUID
21    task_guid: String,
22    /// 评论 GUID
23    comment_guid: String,
24}
25
26impl DeleteCommentRequest {
27    /// 创建新的请求构建器。
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        }
34    }
35
36    /// 执行请求
37    pub async fn execute(self) -> SDKResult<DeleteCommentResponse> {
38        self.execute_with_options(openlark_core::req_option::RequestOption::default())
39            .await
40    }
41
42    /// 执行请求(带选项)
43    pub async fn execute_with_options(
44        self,
45        option: openlark_core::req_option::RequestOption,
46    ) -> SDKResult<DeleteCommentResponse> {
47        // 验证必填字段
48        validate_required!(self.task_guid.trim(), "任务GUID不能为空");
49        validate_required!(self.comment_guid.trim(), "评论GUID不能为空");
50
51        let api_endpoint =
52            TaskApiV2::CommentDelete(self.task_guid.clone(), self.comment_guid.clone());
53        let request = ApiRequest::<DeleteCommentResponse>::delete(api_endpoint.to_url());
54
55        let response =
56            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
57        extract_response_data(response, "删除评论")
58    }
59}
60
61impl ApiResponseTrait for DeleteCommentResponse {
62    fn data_format() -> ResponseFormat {
63        ResponseFormat::Data
64    }
65}
66
67#[cfg(test)]
68#[allow(unused_imports)]
69mod tests {
70    use std::sync::Arc;
71
72    use super::*;
73
74    #[test]
75    fn test_delete_comment_request() {
76        let config = openlark_core::config::Config::builder()
77            .app_id("test")
78            .app_secret("test")
79            .build();
80
81        let request = DeleteCommentRequest::new(
82            Arc::new(config),
83            "task_123".to_string(),
84            "comment_456".to_string(),
85        );
86
87        assert_eq!(request.task_guid, "task_123");
88        assert_eq!(request.comment_guid, "comment_456");
89    }
90}