openapi_rs/api/v1/storage/
api_storage_move.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 ApiStorageMoveRequest {
11    #[serde(rename = "Src")]
12    pub src_path: Option<String>,
13    #[serde(rename = "Dest")]
14    pub dest_path: Option<String>,
15}
16
17impl ApiStorageMoveRequest {
18    pub fn new() -> Self {
19        Default::default()
20    }
21    pub fn with_src_path(mut self, src_path: String) -> Self {
22        self.src_path = Some(src_path);
23        self
24    }
25    pub fn with_dest_path(mut self, dest_path: String) -> Self {
26        self.dest_path = Some(dest_path);
27        self
28    }
29}
30
31#[derive(Debug, Default, Clone, Serialize, Deserialize)]
32#[serde(default)]
33pub struct ApiStorageMoveResponse {}
34
35impl HttpBuilder for ApiStorageMoveRequest {
36    type Response = BaseResponse<ApiStorageMoveResponse>;
37
38    fn builder(self) -> HttpFn<Self::Response> {
39        Box::new(move || {
40            let request_fn: RequestFn = Box::new(move || {
41                let body_content = serde_json::to_vec(&self).unwrap();
42                BaseRequest {
43                    method: Method::POST,
44                    uri: "/api/storage/mv".to_string(),
45                    content_type: Some("application/json".to_string()),
46                    body: Bytes::from(body_content),
47                    ..Default::default()
48                }
49            });
50            let response_fn: AsyncResponseFn<Self::Response> =
51                Box::new(|response: Response| Box::pin(async move { Ok(response.json().await?) }));
52            (request_fn, response_fn)
53        })
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60    use crate::common::client::OpenApiClient;
61    use crate::common::config::{EndpointType, OpenApiConfig};
62    use tracing::info;
63
64    #[tokio::test]
65    async fn test_api_storage_move() -> anyhow::Result<()> {
66        tracing_subscriber::fmt::init();
67        dotenvy::dotenv()?;
68        let config = OpenApiConfig::new().load_from_env()?;
69        let user_id = config.user_id.clone();
70        let mut client = OpenApiClient::new(config).with_endpoint_type(EndpointType::Cloud);
71
72        let http_fn = ApiStorageMoveRequest::new()
73            .with_src_path(format!("/{}/runner.py", user_id))
74            .with_dest_path(format!("/{}/tmp/runner.py", user_id))
75            .builder();
76        let response = client.send(http_fn).await?;
77        info!("response: {:#?}", response);
78
79        Ok(())
80    }
81}