artcoded_api/apis/
timesheet_controller_api.rs

1/*
2 * Artcoded
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`close_timesheet`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CloseTimesheetError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`count`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum CountError {
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`delete_timesheet`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum DeleteTimesheetError {
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`estimate_total_to_be_invoiced_this_month`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum EstimateTotalToBeInvoicedThisMonthError {
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`find_all_grouped_by_year_and_client_name`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum FindAllGroupedByYearAndClientNameError {
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`find_by_id5`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum FindById5Error {
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`generate_invoice`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GenerateInvoiceError {
62    UnknownValue(serde_json::Value),
63}
64
65/// struct for typed errors of method [`reopen_timesheet`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum ReopenTimesheetError {
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed errors of method [`save_or_update_timesheet`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum SaveOrUpdateTimesheetError {
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`save_or_update_timesheet_period`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum SaveOrUpdateTimesheetPeriodError {
83    UnknownValue(serde_json::Value),
84}
85
86/// struct for typed errors of method [`update_settings`]
87#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum UpdateSettingsError {
90    UnknownValue(serde_json::Value),
91}
92
93pub async fn close_timesheet(
94    configuration: &configuration::Configuration,
95    id: &str,
96) -> Result<(), Error<CloseTimesheetError>> {
97    // add a prefix to parameters to efficiently prevent name collisions
98    let p_query_id = id;
99
100    let uri_str = format!("{}/api/timesheet/close", configuration.base_path);
101    let mut req_builder = configuration
102        .client
103        .request(reqwest::Method::POST, &uri_str);
104
105    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
106    if let Some(ref user_agent) = configuration.user_agent {
107        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108    }
109    if let Some(ref token) = configuration.bearer_access_token {
110        req_builder = req_builder.bearer_auth(token.to_owned());
111    };
112
113    let req = req_builder.build()?;
114    let resp = configuration.client.execute(req).await?;
115
116    let status = resp.status();
117
118    if !status.is_client_error() && !status.is_server_error() {
119        Ok(())
120    } else {
121        let content = resp.text().await?;
122        let entity: Option<CloseTimesheetError> = serde_json::from_str(&content).ok();
123        Err(Error::ResponseError(ResponseContent {
124            status,
125            content,
126            entity,
127        }))
128    }
129}
130
131pub async fn count(
132    configuration: &configuration::Configuration,
133) -> Result<models::Count200Response, Error<CountError>> {
134    let uri_str = format!("{}/api/timesheet/count", configuration.base_path);
135    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137    if let Some(ref user_agent) = configuration.user_agent {
138        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
139    }
140    if let Some(ref token) = configuration.bearer_access_token {
141        req_builder = req_builder.bearer_auth(token.to_owned());
142    };
143
144    let req = req_builder.build()?;
145    let resp = configuration.client.execute(req).await?;
146
147    let status = resp.status();
148    let content_type = resp
149        .headers()
150        .get("content-type")
151        .and_then(|v| v.to_str().ok())
152        .unwrap_or("application/octet-stream");
153    let content_type = super::ContentType::from(content_type);
154
155    if !status.is_client_error() && !status.is_server_error() {
156        let content = resp.text().await?;
157        match content_type {
158            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Count200Response`"))),
160            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Count200Response`")))),
161        }
162    } else {
163        let content = resp.text().await?;
164        let entity: Option<CountError> = serde_json::from_str(&content).ok();
165        Err(Error::ResponseError(ResponseContent {
166            status,
167            content,
168            entity,
169        }))
170    }
171}
172
173pub async fn delete_timesheet(
174    configuration: &configuration::Configuration,
175    id: &str,
176) -> Result<(), Error<DeleteTimesheetError>> {
177    // add a prefix to parameters to efficiently prevent name collisions
178    let p_query_id = id;
179
180    let uri_str = format!("{}/api/timesheet", configuration.base_path);
181    let mut req_builder = configuration
182        .client
183        .request(reqwest::Method::DELETE, &uri_str);
184
185    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
186    if let Some(ref user_agent) = configuration.user_agent {
187        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188    }
189    if let Some(ref token) = configuration.bearer_access_token {
190        req_builder = req_builder.bearer_auth(token.to_owned());
191    };
192
193    let req = req_builder.build()?;
194    let resp = configuration.client.execute(req).await?;
195
196    let status = resp.status();
197
198    if !status.is_client_error() && !status.is_server_error() {
199        Ok(())
200    } else {
201        let content = resp.text().await?;
202        let entity: Option<DeleteTimesheetError> = serde_json::from_str(&content).ok();
203        Err(Error::ResponseError(ResponseContent {
204            status,
205            content,
206            entity,
207        }))
208    }
209}
210
211pub async fn estimate_total_to_be_invoiced_this_month(
212    configuration: &configuration::Configuration,
213) -> Result<f64, Error<EstimateTotalToBeInvoicedThisMonthError>> {
214    let uri_str = format!(
215        "{}/api/timesheet/estimate-total-to-be-invoiced-this-month",
216        configuration.base_path
217    );
218    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
219
220    if let Some(ref user_agent) = configuration.user_agent {
221        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
222    }
223    if let Some(ref token) = configuration.bearer_access_token {
224        req_builder = req_builder.bearer_auth(token.to_owned());
225    };
226
227    let req = req_builder.build()?;
228    let resp = configuration.client.execute(req).await?;
229
230    let status = resp.status();
231    let content_type = resp
232        .headers()
233        .get("content-type")
234        .and_then(|v| v.to_str().ok())
235        .unwrap_or("application/octet-stream");
236    let content_type = super::ContentType::from(content_type);
237
238    if !status.is_client_error() && !status.is_server_error() {
239        let content = resp.text().await?;
240        match content_type {
241            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
242            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `f64`"))),
243            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `f64`")))),
244        }
245    } else {
246        let content = resp.text().await?;
247        let entity: Option<EstimateTotalToBeInvoicedThisMonthError> =
248            serde_json::from_str(&content).ok();
249        Err(Error::ResponseError(ResponseContent {
250            status,
251            content,
252            entity,
253        }))
254    }
255}
256
257pub async fn find_all_grouped_by_year_and_client_name(
258    configuration: &configuration::Configuration,
259    only_active_client: Option<bool>,
260) -> Result<
261    std::collections::HashMap<String, std::collections::HashMap<String, Vec<models::Timesheet>>>,
262    Error<FindAllGroupedByYearAndClientNameError>,
263> {
264    // add a prefix to parameters to efficiently prevent name collisions
265    let p_query_only_active_client = only_active_client;
266
267    let uri_str = format!("{}/api/timesheet", configuration.base_path);
268    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
269
270    if let Some(ref param_value) = p_query_only_active_client {
271        req_builder = req_builder.query(&[("onlyActiveClient", &param_value.to_string())]);
272    }
273    if let Some(ref user_agent) = configuration.user_agent {
274        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275    }
276    if let Some(ref token) = configuration.bearer_access_token {
277        req_builder = req_builder.bearer_auth(token.to_owned());
278    };
279
280    let req = req_builder.build()?;
281    let resp = configuration.client.execute(req).await?;
282
283    let status = resp.status();
284    let content_type = resp
285        .headers()
286        .get("content-type")
287        .and_then(|v| v.to_str().ok())
288        .unwrap_or("application/octet-stream");
289    let content_type = super::ContentType::from(content_type);
290
291    if !status.is_client_error() && !status.is_server_error() {
292        let content = resp.text().await?;
293        match content_type {
294            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
295            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, std::collections::HashMap&lt;String, Vec&lt;models::Timesheet&gt;&gt;&gt;`"))),
296            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, std::collections::HashMap&lt;String, Vec&lt;models::Timesheet&gt;&gt;&gt;`")))),
297        }
298    } else {
299        let content = resp.text().await?;
300        let entity: Option<FindAllGroupedByYearAndClientNameError> =
301            serde_json::from_str(&content).ok();
302        Err(Error::ResponseError(ResponseContent {
303            status,
304            content,
305            entity,
306        }))
307    }
308}
309
310pub async fn find_by_id5(
311    configuration: &configuration::Configuration,
312    id: &str,
313) -> Result<models::Timesheet, Error<FindById5Error>> {
314    // add a prefix to parameters to efficiently prevent name collisions
315    let p_query_id = id;
316
317    let uri_str = format!("{}/api/timesheet/by-id", configuration.base_path);
318    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
319
320    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
321    if let Some(ref user_agent) = configuration.user_agent {
322        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
323    }
324    if let Some(ref token) = configuration.bearer_access_token {
325        req_builder = req_builder.bearer_auth(token.to_owned());
326    };
327
328    let req = req_builder.build()?;
329    let resp = configuration.client.execute(req).await?;
330
331    let status = resp.status();
332    let content_type = resp
333        .headers()
334        .get("content-type")
335        .and_then(|v| v.to_str().ok())
336        .unwrap_or("application/octet-stream");
337    let content_type = super::ContentType::from(content_type);
338
339    if !status.is_client_error() && !status.is_server_error() {
340        let content = resp.text().await?;
341        match content_type {
342            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
343            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Timesheet`"))),
344            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Timesheet`")))),
345        }
346    } else {
347        let content = resp.text().await?;
348        let entity: Option<FindById5Error> = serde_json::from_str(&content).ok();
349        Err(Error::ResponseError(ResponseContent {
350            status,
351            content,
352            entity,
353        }))
354    }
355}
356
357pub async fn generate_invoice(
358    configuration: &configuration::Configuration,
359    id: &str,
360) -> Result<models::Timesheet, Error<GenerateInvoiceError>> {
361    // add a prefix to parameters to efficiently prevent name collisions
362    let p_query_id = id;
363
364    let uri_str = format!("{}/api/timesheet/generate-invoice", configuration.base_path);
365    let mut req_builder = configuration
366        .client
367        .request(reqwest::Method::POST, &uri_str);
368
369    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
370    if let Some(ref user_agent) = configuration.user_agent {
371        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
372    }
373    if let Some(ref token) = configuration.bearer_access_token {
374        req_builder = req_builder.bearer_auth(token.to_owned());
375    };
376
377    let req = req_builder.build()?;
378    let resp = configuration.client.execute(req).await?;
379
380    let status = resp.status();
381    let content_type = resp
382        .headers()
383        .get("content-type")
384        .and_then(|v| v.to_str().ok())
385        .unwrap_or("application/octet-stream");
386    let content_type = super::ContentType::from(content_type);
387
388    if !status.is_client_error() && !status.is_server_error() {
389        let content = resp.text().await?;
390        match content_type {
391            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
392            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Timesheet`"))),
393            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Timesheet`")))),
394        }
395    } else {
396        let content = resp.text().await?;
397        let entity: Option<GenerateInvoiceError> = serde_json::from_str(&content).ok();
398        Err(Error::ResponseError(ResponseContent {
399            status,
400            content,
401            entity,
402        }))
403    }
404}
405
406pub async fn reopen_timesheet(
407    configuration: &configuration::Configuration,
408    id: &str,
409) -> Result<(), Error<ReopenTimesheetError>> {
410    // add a prefix to parameters to efficiently prevent name collisions
411    let p_query_id = id;
412
413    let uri_str = format!("{}/api/timesheet/reopen", configuration.base_path);
414    let mut req_builder = configuration
415        .client
416        .request(reqwest::Method::POST, &uri_str);
417
418    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
419    if let Some(ref user_agent) = configuration.user_agent {
420        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
421    }
422    if let Some(ref token) = configuration.bearer_access_token {
423        req_builder = req_builder.bearer_auth(token.to_owned());
424    };
425
426    let req = req_builder.build()?;
427    let resp = configuration.client.execute(req).await?;
428
429    let status = resp.status();
430
431    if !status.is_client_error() && !status.is_server_error() {
432        Ok(())
433    } else {
434        let content = resp.text().await?;
435        let entity: Option<ReopenTimesheetError> = serde_json::from_str(&content).ok();
436        Err(Error::ResponseError(ResponseContent {
437            status,
438            content,
439            entity,
440        }))
441    }
442}
443
444pub async fn save_or_update_timesheet(
445    configuration: &configuration::Configuration,
446    timesheet: models::Timesheet,
447) -> Result<models::Timesheet, Error<SaveOrUpdateTimesheetError>> {
448    // add a prefix to parameters to efficiently prevent name collisions
449    let p_body_timesheet = timesheet;
450
451    let uri_str = format!("{}/api/timesheet", configuration.base_path);
452    let mut req_builder = configuration
453        .client
454        .request(reqwest::Method::POST, &uri_str);
455
456    if let Some(ref user_agent) = configuration.user_agent {
457        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
458    }
459    if let Some(ref token) = configuration.bearer_access_token {
460        req_builder = req_builder.bearer_auth(token.to_owned());
461    };
462    req_builder = req_builder.json(&p_body_timesheet);
463
464    let req = req_builder.build()?;
465    let resp = configuration.client.execute(req).await?;
466
467    let status = resp.status();
468    let content_type = resp
469        .headers()
470        .get("content-type")
471        .and_then(|v| v.to_str().ok())
472        .unwrap_or("application/octet-stream");
473    let content_type = super::ContentType::from(content_type);
474
475    if !status.is_client_error() && !status.is_server_error() {
476        let content = resp.text().await?;
477        match content_type {
478            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
479            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Timesheet`"))),
480            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Timesheet`")))),
481        }
482    } else {
483        let content = resp.text().await?;
484        let entity: Option<SaveOrUpdateTimesheetError> = serde_json::from_str(&content).ok();
485        Err(Error::ResponseError(ResponseContent {
486            status,
487            content,
488            entity,
489        }))
490    }
491}
492
493pub async fn save_or_update_timesheet_period(
494    configuration: &configuration::Configuration,
495    id: &str,
496    timesheet_period: models::TimesheetPeriod,
497) -> Result<models::TimesheetPeriod, Error<SaveOrUpdateTimesheetPeriodError>> {
498    // add a prefix to parameters to efficiently prevent name collisions
499    let p_query_id = id;
500    let p_body_timesheet_period = timesheet_period;
501
502    let uri_str = format!("{}/api/timesheet/save-period", configuration.base_path);
503    let mut req_builder = configuration
504        .client
505        .request(reqwest::Method::POST, &uri_str);
506
507    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
508    if let Some(ref user_agent) = configuration.user_agent {
509        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
510    }
511    if let Some(ref token) = configuration.bearer_access_token {
512        req_builder = req_builder.bearer_auth(token.to_owned());
513    };
514    req_builder = req_builder.json(&p_body_timesheet_period);
515
516    let req = req_builder.build()?;
517    let resp = configuration.client.execute(req).await?;
518
519    let status = resp.status();
520    let content_type = resp
521        .headers()
522        .get("content-type")
523        .and_then(|v| v.to_str().ok())
524        .unwrap_or("application/octet-stream");
525    let content_type = super::ContentType::from(content_type);
526
527    if !status.is_client_error() && !status.is_server_error() {
528        let content = resp.text().await?;
529        match content_type {
530            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
531            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetPeriod`"))),
532            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetPeriod`")))),
533        }
534    } else {
535        let content = resp.text().await?;
536        let entity: Option<SaveOrUpdateTimesheetPeriodError> = serde_json::from_str(&content).ok();
537        Err(Error::ResponseError(ResponseContent {
538            status,
539            content,
540            entity,
541        }))
542    }
543}
544
545pub async fn update_settings(
546    configuration: &configuration::Configuration,
547    timesheet_settings_form: models::TimesheetSettingsForm,
548) -> Result<models::Timesheet, Error<UpdateSettingsError>> {
549    // add a prefix to parameters to efficiently prevent name collisions
550    let p_body_timesheet_settings_form = timesheet_settings_form;
551
552    let uri_str = format!("{}/api/timesheet/settings", configuration.base_path);
553    let mut req_builder = configuration
554        .client
555        .request(reqwest::Method::POST, &uri_str);
556
557    if let Some(ref user_agent) = configuration.user_agent {
558        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
559    }
560    if let Some(ref token) = configuration.bearer_access_token {
561        req_builder = req_builder.bearer_auth(token.to_owned());
562    };
563    req_builder = req_builder.json(&p_body_timesheet_settings_form);
564
565    let req = req_builder.build()?;
566    let resp = configuration.client.execute(req).await?;
567
568    let status = resp.status();
569    let content_type = resp
570        .headers()
571        .get("content-type")
572        .and_then(|v| v.to_str().ok())
573        .unwrap_or("application/octet-stream");
574    let content_type = super::ContentType::from(content_type);
575
576    if !status.is_client_error() && !status.is_server_error() {
577        let content = resp.text().await?;
578        match content_type {
579            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
580            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Timesheet`"))),
581            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Timesheet`")))),
582        }
583    } else {
584        let content = resp.text().await?;
585        let entity: Option<UpdateSettingsError> = serde_json::from_str(&content).ok();
586        Err(Error::ResponseError(ResponseContent {
587            status,
588            content,
589            entity,
590        }))
591    }
592}