voltaria_sdk/api/resources/drawdowns/drawdowns.rs
1use crate::api::*;
2use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
3use reqwest::Method;
4
5pub struct DrawdownsClient {
6 pub http_client: HttpClient,
7}
8
9impl DrawdownsClient {
10 pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
11 Ok(Self {
12 http_client: HttpClient::new(config.clone())?,
13 })
14 }
15
16 /// Retrieve a list of drawdowns.
17 ///
18 /// # Arguments
19 ///
20 /// * `order_by` - Field to order the results by, e.g., 'created_at:desc,updated_at:asc'
21 /// * `q` - Query string for filtering. Format: "field:operator:value;...". Supported fields: . Supported operators: is, in, not_in, contains, not_contains, like, not_like, ilike, not_ilike, gt, gte, lt, lte, starts_with, ends_with, is_null, is_not_null.
22 /// * `options` - Additional request options such as headers, timeout, etc.
23 ///
24 /// # Returns
25 ///
26 /// JSON response from the API
27 pub async fn list_drawdowns(
28 &self,
29 request: &ListDrawdownsQueryRequest,
30 options: Option<RequestOptions>,
31 ) -> Result<PaginatedResponseDrawdownResponse, ApiError> {
32 self.http_client
33 .execute_request(
34 Method::GET,
35 "v2/drawdowns",
36 None,
37 QueryBuilder::new()
38 .serialize("page", request.page.clone())
39 .serialize("page_size", request.page_size.clone())
40 .serialize("order_by", request.order_by.clone())
41 .serialize("q", request.q.clone())
42 .build(),
43 options,
44 )
45 .await
46 }
47
48 /// Create a new drawdown request.
49 ///
50 /// # Arguments
51 ///
52 /// * `options` - Additional request options such as headers, timeout, etc.
53 ///
54 /// # Returns
55 ///
56 /// JSON response from the API
57 pub async fn create_drawdown_request(
58 &self,
59 request: &DrawdownCreatePayload,
60 options: Option<RequestOptions>,
61 ) -> Result<DrawdownResponse, ApiError> {
62 self.http_client
63 .execute_request(
64 Method::POST,
65 "v2/drawdowns",
66 Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
67 None,
68 options,
69 )
70 .await
71 }
72
73 /// Retrieve all checklist items for a specific drawdown
74 ///
75 /// # Arguments
76 ///
77 /// * `order_by` - Field to order the results by, e.g., 'created_at:desc,updated_at:asc'
78 /// * `q` - Query string for filtering. Format: "field:operator:value;...". Supported fields: . Supported operators: is, in, not_in, contains, not_contains, like, not_like, ilike, not_ilike, gt, gte, lt, lte, starts_with, ends_with, is_null, is_not_null.
79 /// * `options` - Additional request options such as headers, timeout, etc.
80 ///
81 /// # Returns
82 ///
83 /// JSON response from the API
84 pub async fn list_drawdown_checklists(
85 &self,
86 drawdown_id: &str,
87 request: &ListDrawdownChecklistsQueryRequest,
88 options: Option<RequestOptions>,
89 ) -> Result<PaginatedResponseDrawdownChecklistResponse, ApiError> {
90 self.http_client
91 .execute_request(
92 Method::GET,
93 &format!("v2/drawdowns/{}/checklists", drawdown_id),
94 None,
95 QueryBuilder::new()
96 .serialize("page", request.page.clone())
97 .serialize("page_size", request.page_size.clone())
98 .serialize("order_by", request.order_by.clone())
99 .serialize("q", request.q.clone())
100 .build(),
101 options,
102 )
103 .await
104 }
105}