openapi_rs/api/v1/sync/
system_sync_stop_task.rs

1use crate::common::define::{
2    AsyncResponseFn, BaseRequest, BaseResponse, HttpBuilder, HttpFn, RequestFn,
3};
4use bytes::Bytes;
5use reqwest::{Method, Response};
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Default, Clone, Serialize, Deserialize)]
9#[serde(default)]
10pub struct SystemStopTaskRequest {
11    #[serde(rename = "JobId")]
12    pub job_id: Option<String>,
13    #[serde(rename = "Mode")]
14    pub mode: Option<isize>,
15}
16
17impl SystemStopTaskRequest {
18    pub fn new() -> Self {
19        Self::default()
20    }
21    pub fn with_job_ids(mut self, job_id: String) -> Self {
22        self.job_id = Some(job_id);
23        self
24    }
25    pub fn with_mode(mut self, mode: isize) -> Self {
26        self.mode = Some(mode);
27        self
28    }
29}
30
31#[derive(Debug, Default, Clone, Serialize, Deserialize)]
32#[serde(default)]
33pub struct SystemStopTaskResponse {}
34
35impl HttpBuilder for SystemStopTaskRequest {
36    type Response = BaseResponse<SystemStopTaskResponse>;
37    fn builder(self) -> HttpFn<Self::Response> {
38        Box::new(move || {
39            let request_fn: RequestFn = Box::new(move || BaseRequest {
40                method: Method::POST,
41                uri: format!("/system/sync-task/{:?}/stop", self.job_id),
42                body: Bytes::from(serde_json::to_vec(&self).unwrap()),
43                ..Default::default()
44            });
45            let response_fn: AsyncResponseFn<Self::Response> =
46                Box::new(|response: Response| Box::pin(async move { Ok(response.json().await?) }));
47            (request_fn, response_fn)
48        })
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55    use crate::common::client::OpenApiClient;
56    use crate::common::config::{EndpointType, OpenApiConfig};
57    use tracing::info;
58
59    #[tokio::test]
60    async fn test_system_sync_stop_task() -> anyhow::Result<()> {
61        tracing_subscriber::fmt::init();
62        dotenvy::dotenv()?;
63        let config = OpenApiConfig::new().load_from_env()?;
64        let mut client = OpenApiClient::new(config).with_endpoint_type(EndpointType::Sync);
65
66        let http_fn = SystemStopTaskRequest::new()
67            .with_job_ids("123".to_string())
68            .builder();
69        let response = client.send(http_fn).await?;
70        info!("response: {:#?}", response);
71
72        Ok(())
73    }
74}