openapi_rs/api/v1/storage/
api_storage_stat.rs1use crate::common::define::{
2 AsyncResponseFn, BaseRequest, BaseResponse, HttpBuilder, HttpFn, RequestFn,
3};
4use crate::model::file::FileInfo;
5use reqwest::{Method, Response};
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9#[derive(Debug, Default, Clone, Serialize, Deserialize)]
10#[serde(default)]
11pub struct ApiStorageStatRequest {
12 #[serde(rename = "Path")]
13 pub path: Option<String>,
14}
15
16impl ApiStorageStatRequest {
17 pub fn new() -> Self {
18 Self::default()
19 }
20 pub fn with_path(mut self, path: String) -> Self {
21 self.path = Some(path);
22 self
23 }
24}
25
26#[derive(Debug, Default, Clone, Serialize, Deserialize)]
27#[serde(default)]
28pub struct ApiStorageStatResponse {
29 #[serde(rename = "File")]
30 pub file: Option<FileInfo>,
31}
32
33impl HttpBuilder for ApiStorageStatRequest {
34 type Response = BaseResponse<ApiStorageStatResponse>;
35 fn builder(self) -> HttpFn<Self::Response> {
36 Box::new(move || {
37 let request_fn: RequestFn = Box::new(move || {
38 let mut queries = HashMap::new();
39 if let Some(path) = self.path {
40 queries.insert("Path".to_string(), path);
41 }
42 BaseRequest {
43 method: Method::GET,
44 uri: "/api/storage/stat".to_string(),
45 queries: Some(queries),
46 ..Default::default()
47 }
48 });
49 let response_fn: AsyncResponseFn<Self::Response> =
50 Box::new(|response: Response| Box::pin(async move { Ok(response.json().await?) }));
51 (request_fn, response_fn)
52 })
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use crate::common::client::OpenApiClient;
60 use crate::common::config::{EndpointType, OpenApiConfig};
61 use tracing::info;
62
63 #[tokio::test]
64 async fn test_api_storage_stat() -> anyhow::Result<()> {
65 tracing_subscriber::fmt::init();
66 dotenvy::dotenv()?;
67 let config = OpenApiConfig::new().load_from_env()?;
68 let user_id = config.user_id.clone();
69 let mut client = OpenApiClient::new(config).with_endpoint_type(EndpointType::Cloud);
70
71 let http_fn = ApiStorageStatRequest::new()
72 .with_path(format!("/{}/runner.py", user_id))
73 .builder();
74 let response = client.send(http_fn).await?;
75 info!("response: {:#?}", response);
76
77 Ok(())
78 }
79}