Skip to main content

openlark_workflow/
service.rs

1use openlark_core::config::Config;
2use std::sync::Arc;
3
4/// WorkflowService:工作流服务的统一入口
5///
6/// 提供对任务、审批、看板 API 的访问能力
7#[derive(Clone)]
8#[allow(dead_code)]
9pub struct WorkflowService {
10    config: Arc<Config>,
11}
12
13impl WorkflowService {
14    pub fn new(config: Config) -> Self {
15        Self {
16            config: Arc::new(config),
17        }
18    }
19
20    #[cfg(feature = "v1")]
21    pub fn v1(&self) -> crate::v1::TaskV1 {
22        crate::v1::TaskV1::new(self.config.clone())
23    }
24
25    #[cfg(feature = "v2")]
26    pub fn v2(&self) -> crate::v2::TaskV2 {
27        crate::v2::TaskV2::new(self.config.clone())
28    }
29
30    #[cfg(feature = "v2")]
31    pub fn task(&self) -> crate::v2::task::Task {
32        crate::v2::task::Task::new(self.config.clone())
33    }
34
35    #[cfg(feature = "v2")]
36    pub fn tasklist(&self) -> crate::v2::tasklist::Tasklist {
37        crate::v2::tasklist::Tasklist::new(self.config.clone())
38    }
39}
40
41#[cfg(test)]
42#[allow(unused_imports)]
43mod tests {
44
45    #[test]
46    fn test_serialization_roundtrip() {
47        // 基础序列化测试
48        let json = r#"{"test": "value"}"#;
49        assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
50    }
51
52    #[test]
53    fn test_deserialization_from_json() {
54        // 基础反序列化测试
55        let json = r#"{"field": "data"}"#;
56        let value: serde_json::Value = serde_json::from_str(json).unwrap();
57        assert_eq!(value["field"], "data");
58    }
59}