voltaria_sdk/api/resources/documents/documents.rs
1use crate::api::*;
2use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
3use reqwest::Method;
4
5pub struct DocumentsClient {
6 pub http_client: HttpClient,
7}
8
9impl DocumentsClient {
10 pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
11 Ok(Self {
12 http_client: HttpClient::new(config.clone())?,
13 })
14 }
15
16 /// Retrieve all documents linked to a client.
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: id, client_id, loan_id, installment_id, waterfall_id, category, file_name, document_date, folder_path. 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_documents(
28 &self,
29 request: &ListDocumentsQueryRequest,
30 options: Option<RequestOptions>,
31 ) -> Result<PaginatedResponseDocumentResponse, ApiError> {
32 self.http_client
33 .execute_request(
34 Method::GET,
35 "v2/documents",
36 None,
37 QueryBuilder::new()
38 .serialize("client_id", request.client_id.clone())
39 .serialize("loan_id", request.loan_id.clone())
40 .serialize("installment_id", request.installment_id.clone())
41 .serialize("waterfall_id", request.waterfall_id.clone())
42 .serialize("page", request.page.clone())
43 .serialize("page_size", request.page_size.clone())
44 .serialize("order_by", request.order_by.clone())
45 .serialize("q", request.q.clone())
46 .build(),
47 options,
48 )
49 .await
50 }
51
52 /// Upload a new document related to a client or loan, such as financial statements or KYC files.
53 ///
54 /// # Arguments
55 ///
56 /// * `options` - Additional request options such as headers, timeout, etc.
57 ///
58 /// # Returns
59 ///
60 /// JSON response from the API
61 pub async fn upload_document(
62 &self,
63 request: &UploadDocumentRequest,
64 options: Option<RequestOptions>,
65 ) -> Result<DocumentResponse, ApiError> {
66 self.http_client
67 .execute_multipart_request(
68 Method::POST,
69 "v2/documents",
70 request.clone().to_multipart(),
71 QueryBuilder::new()
72 .serialize("client_id", request.client_id.clone())
73 .serialize("loan_id", request.loan_id.clone())
74 .serialize("installment_id", request.installment_id.clone())
75 .serialize("waterfall_id", request.waterfall_id.clone())
76 .build(),
77 options,
78 )
79 .await
80 }
81
82 /// Retrieve all available document categories.
83 ///
84 /// # Arguments
85 ///
86 /// * `options` - Additional request options such as headers, timeout, etc.
87 ///
88 /// # Returns
89 ///
90 /// JSON response from the API
91 pub async fn get_available_document_categories(
92 &self,
93 options: Option<RequestOptions>,
94 ) -> Result<AvailableDocumentCategoriesResponse, ApiError> {
95 self.http_client
96 .execute_request(
97 Method::GET,
98 "v2/documents/available-categories",
99 None,
100 None,
101 options,
102 )
103 .await
104 }
105
106 /// Retrieve details for a specific document using its document ID.
107 ///
108 /// # Arguments
109 ///
110 /// * `options` - Additional request options such as headers, timeout, etc.
111 ///
112 /// # Returns
113 ///
114 /// JSON response from the API
115 pub async fn get_document_by_id(
116 &self,
117 document_id: &str,
118 options: Option<RequestOptions>,
119 ) -> Result<DocumentResponse, ApiError> {
120 self.http_client
121 .execute_request(
122 Method::GET,
123 &format!("v2/documents/{}", document_id),
124 None,
125 None,
126 options,
127 )
128 .await
129 }
130
131 /// Delete a specific document by using its document ID.
132 ///
133 /// # Arguments
134 ///
135 /// * `options` - Additional request options such as headers, timeout, etc.
136 ///
137 /// # Returns
138 ///
139 /// Empty response
140 pub async fn delete_document(
141 &self,
142 document_id: &str,
143 options: Option<RequestOptions>,
144 ) -> Result<(), ApiError> {
145 self.http_client
146 .execute_request(
147 Method::DELETE,
148 &format!("v2/documents/{}", document_id),
149 None,
150 None,
151 options,
152 )
153 .await
154 }
155}