1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetCategoriesError {
22 Status404(models::ErrorResponse),
23 DefaultResponse(models::ErrorResponse),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetCategoryByIdError {
31 Status404(models::ErrorResponse),
32 DefaultResponse(models::ErrorResponse),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetMonthCategoryByIdError {
40 Status404(models::ErrorResponse),
41 DefaultResponse(models::ErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum UpdateCategoryError {
49 Status400(models::ErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum UpdateMonthCategoryError {
57 Status400(models::ErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61
62pub async fn get_categories(configuration: &configuration::Configuration, budget_id: &str, last_knowledge_of_server: Option<i64>) -> Result<models::CategoriesResponse, Error<GetCategoriesError>> {
64 let local_var_configuration = configuration;
65
66 let local_var_client = &local_var_configuration.client;
67
68 let local_var_uri_str = format!("{}/budgets/{budget_id}/categories", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
69 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
70
71 if let Some(ref local_var_str) = last_knowledge_of_server {
72 local_var_req_builder = local_var_req_builder.query(&[("last_knowledge_of_server", &local_var_str.to_string())]);
73 }
74 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
75 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
76 }
77 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
78 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
79 };
80
81 let local_var_req = local_var_req_builder.build()?;
82 let local_var_resp = local_var_client.execute(local_var_req).await?;
83
84 let local_var_status = local_var_resp.status();
85 let local_var_content = local_var_resp.text().await?;
86
87 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
88 serde_json::from_str(&local_var_content).map_err(Error::from)
89 } else {
90 let local_var_entity: Option<GetCategoriesError> = serde_json::from_str(&local_var_content).ok();
91 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
92 Err(Error::ResponseError(local_var_error))
93 }
94}
95
96pub async fn get_category_by_id(configuration: &configuration::Configuration, budget_id: &str, category_id: &str) -> Result<models::CategoryResponse, Error<GetCategoryByIdError>> {
98 let local_var_configuration = configuration;
99
100 let local_var_client = &local_var_configuration.client;
101
102 let local_var_uri_str = format!("{}/budgets/{budget_id}/categories/{category_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), category_id=crate::apis::urlencode(category_id));
103 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
104
105 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
106 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
107 }
108 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
109 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
110 };
111
112 let local_var_req = local_var_req_builder.build()?;
113 let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115 let local_var_status = local_var_resp.status();
116 let local_var_content = local_var_resp.text().await?;
117
118 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
119 serde_json::from_str(&local_var_content).map_err(Error::from)
120 } else {
121 let local_var_entity: Option<GetCategoryByIdError> = serde_json::from_str(&local_var_content).ok();
122 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
123 Err(Error::ResponseError(local_var_error))
124 }
125}
126
127pub async fn get_month_category_by_id(configuration: &configuration::Configuration, budget_id: &str, month: String, category_id: &str) -> Result<models::CategoryResponse, Error<GetMonthCategoryByIdError>> {
129 let local_var_configuration = configuration;
130
131 let local_var_client = &local_var_configuration.client;
132
133 let local_var_uri_str = format!("{}/budgets/{budget_id}/months/{month}/categories/{category_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), month=month, category_id=crate::apis::urlencode(category_id));
134 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
135
136 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
137 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138 }
139 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
140 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
141 };
142
143 let local_var_req = local_var_req_builder.build()?;
144 let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146 let local_var_status = local_var_resp.status();
147 let local_var_content = local_var_resp.text().await?;
148
149 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150 serde_json::from_str(&local_var_content).map_err(Error::from)
151 } else {
152 let local_var_entity: Option<GetMonthCategoryByIdError> = serde_json::from_str(&local_var_content).ok();
153 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
154 Err(Error::ResponseError(local_var_error))
155 }
156}
157
158pub async fn update_category(configuration: &configuration::Configuration, budget_id: &str, category_id: &str, data: models::PatchCategoryWrapper) -> Result<models::SaveCategoryResponse, Error<UpdateCategoryError>> {
160 let local_var_configuration = configuration;
161
162 let local_var_client = &local_var_configuration.client;
163
164 let local_var_uri_str = format!("{}/budgets/{budget_id}/categories/{category_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), category_id=crate::apis::urlencode(category_id));
165 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
166
167 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
168 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
169 }
170 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
171 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
172 };
173 local_var_req_builder = local_var_req_builder.json(&data);
174
175 let local_var_req = local_var_req_builder.build()?;
176 let local_var_resp = local_var_client.execute(local_var_req).await?;
177
178 let local_var_status = local_var_resp.status();
179 let local_var_content = local_var_resp.text().await?;
180
181 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
182 serde_json::from_str(&local_var_content).map_err(Error::from)
183 } else {
184 let local_var_entity: Option<UpdateCategoryError> = serde_json::from_str(&local_var_content).ok();
185 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
186 Err(Error::ResponseError(local_var_error))
187 }
188}
189
190pub async fn update_month_category(configuration: &configuration::Configuration, budget_id: &str, month: String, category_id: &str, data: models::PatchMonthCategoryWrapper) -> Result<models::SaveCategoryResponse, Error<UpdateMonthCategoryError>> {
192 let local_var_configuration = configuration;
193
194 let local_var_client = &local_var_configuration.client;
195
196 let local_var_uri_str = format!("{}/budgets/{budget_id}/months/{month}/categories/{category_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), month=month, category_id=crate::apis::urlencode(category_id));
197 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
198
199 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
200 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
201 }
202 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
203 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
204 };
205 local_var_req_builder = local_var_req_builder.json(&data);
206
207 let local_var_req = local_var_req_builder.build()?;
208 let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content = local_var_resp.text().await?;
212
213 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214 serde_json::from_str(&local_var_content).map_err(Error::from)
215 } else {
216 let local_var_entity: Option<UpdateMonthCategoryError> = serde_json::from_str(&local_var_content).ok();
217 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
218 Err(Error::ResponseError(local_var_error))
219 }
220}
221