openapi_rs/api/v1/sync/
system_sync_update_task_state.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 SystemSyncUpdateTaskStateRequest {
11    #[serde(rename = "JobId")]
12    pub job_id: Option<String>,
13    #[serde(rename = "FileSyncState")]
14    pub file_sync_state: Option<String>,
15}
16
17impl SystemSyncUpdateTaskStateRequest {
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_file_sync_state(mut self, file_sync_state: String) -> Self {
26        self.file_sync_state = Some(file_sync_state);
27        self
28    }
29}
30
31#[derive(Debug, Default, Clone, Serialize, Deserialize)]
32#[serde(default)]
33pub struct SystemSyncUpdateTaskStateResponse {}
34
35impl HttpBuilder for SystemSyncUpdateTaskStateRequest {
36    type Response = BaseResponse<SystemSyncUpdateTaskStateResponse>;
37    fn builder(self) -> HttpFn<Self::Response> {
38        Box::new(move || {
39            let request_fn: RequestFn = Box::new(move || BaseRequest {
40                method: Method::PATCH,
41                uri: format!("/system/sync-task/{:?}/state", 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_update_task_state() -> 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 = SystemSyncUpdateTaskStateRequest::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}