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