openlark-workflow 0.20.0

OpenLark 工作流模块 - 提供飞书任务/审批/看板 API
Documentation
//! 获取任务评论详情(v1)
//!
//! docPath: <https://open.feishu.cn/document/server-docs/docs/task-v1/taskcomment/get>

use openlark_core::{
    SDKResult,
    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
    config::Config,
};
use serde::Deserialize;
use std::sync::Arc;

/// 任务评论详情(v1)
#[derive(Debug, Clone, Deserialize)]
/// 任务评论详情响应。
pub struct GetTaskCommentResponseV1 {
    /// 评论 ID
    pub comment_id: String,
    /// 评论内容
    pub content: String,
    /// 创建者用户 ID
    pub creator_id: String,
    /// 创建时间
    pub created_at: Option<String>,
    /// 父评论 ID
    pub parent_id: Option<String>,
}

/// 获取任务评论详情请求(v1)
#[derive(Debug, Clone)]
/// 获取任务评论详情请求构建器。
pub struct GetTaskCommentRequestV1 {
    config: Arc<Config>,
    task_id: String,
    comment_id: String,
}

impl GetTaskCommentRequestV1 {
    /// 创建新的请求构建器。
    pub fn new(
        config: Arc<Config>,
        task_id: impl Into<String>,
        comment_id: impl Into<String>,
    ) -> Self {
        Self {
            config,
            task_id: task_id.into(),
            comment_id: comment_id.into(),
        }
    }

    /// 执行请求
    pub async fn execute(self) -> SDKResult<GetTaskCommentResponseV1> {
        self.execute_with_options(openlark_core::req_option::RequestOption::default())
            .await
    }

    /// 执行请求(带选项)
    pub async fn execute_with_options(
        self,
        option: openlark_core::req_option::RequestOption,
    ) -> SDKResult<GetTaskCommentResponseV1> {
        let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
            self.task_id.clone(),
            self.comment_id.clone(),
        );
        let request = ApiRequest::<GetTaskCommentResponseV1>::get(api_endpoint.to_url());

        openlark_core::http::Transport::request_typed(
            request,
            &self.config,
            Some(option),
            "响应数据为空",
        )
        .await
    }
}

impl ApiResponseTrait for GetTaskCommentResponseV1 {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

#[cfg(test)]
#[allow(unused_imports)]
mod tests {

    #[test]
    fn test_get_task_comment_v1_url() {
        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskCommentGet(
            "task_123".to_string(),
            "comment_456".to_string(),
        );
        assert_eq!(
            endpoint.to_url(),
            "/open-apis/task/v1/tasks/task_123/comments/comment_456"
        );
    }
}