openapi_rs/api/v1/storage/
api_storage_remove.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 ApiStorageRemoveRequest {
11 #[serde(rename = "Path")]
12 pub path: Option<String>,
13 #[serde(rename = "IgnoreNotExist")]
14 pub ignore_not_exist: Option<bool>,
15}
16
17impl ApiStorageRemoveRequest {
18 pub fn new() -> Self {
19 Default::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_not_exist(mut self, ignore_not_exist: bool) -> Self {
26 self.ignore_not_exist = Some(ignore_not_exist);
27 self
28 }
29}
30
31#[derive(Debug, Default, Clone, Serialize, Deserialize)]
32#[serde(default)]
33pub struct ApiStorageRemoveResponse {}
34
35impl HttpBuilder for ApiStorageRemoveRequest {
36 type Response = BaseResponse<ApiStorageRemoveResponse>;
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/rm".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_remove() -> 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 = ApiStorageRemoveRequest::new()
73 .with_path(format!("/{}/runner.py", user_id))
74 .with_ignore_not_exist(true)
75 .builder();
76 let response = client.send(http_fn).await?;
77 info!("response: {:#?}", response);
78
79 Ok(())
80 }
81}