openapi_rs/api/v1/storage/
api_storage_mkdir.rs1use 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 ApiStorageMkDirRequest {
11 #[serde(rename = "Path")]
12 pub path: Option<String>,
13 #[serde(rename = "IgnoreExist")]
14 pub ignore_exist: Option<bool>,
15}
16
17impl ApiStorageMkDirRequest {
18 pub fn new() -> Self {
19 Self::default()
20 }
21 pub fn with_path(mut self, path: String) -> Self {
22 self.path = Some(path);
23 self
24 }
25 pub fn with_ignore_exist(mut self, ignore_exist: bool) -> Self {
26 self.ignore_exist = Some(ignore_exist);
27 self
28 }
29}
30
31#[derive(Debug, Default, Clone, Serialize, Deserialize)]
32#[serde(default)]
33pub struct ApiStorageMkDirResponse {}
34
35impl HttpBuilder for ApiStorageMkDirRequest {
36 type Response = BaseResponse<ApiStorageMkDirResponse>;
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: "/api/storage/mkdir".to_string(),
42 body: Bytes::from(serde_json::to_string(&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_api_storage_mkdir() -> anyhow::Result<()> {
61 tracing_subscriber::fmt::init();
62 dotenvy::dotenv()?;
63 let config = OpenApiConfig::new().load_from_env()?;
64 let user_id = config.user_id.clone();
65 let mut client = OpenApiClient::new(config).with_endpoint_type(EndpointType::Cloud);
66
67 let http_fn = ApiStorageMkDirRequest::new()
68 .with_path(format!("/{}/abcd", user_id))
69 .builder();
70 let response = client.send(http_fn).await?;
71 info!("response: {:#?}", response);
72
73 Ok(())
74 }
75}