/*
* Kimai - API
*
* JSON API for the Kimai time-tracking software. Read our [API documentation](https://www.kimai.org/documentation/rest-api.html) and download the [Open API definition](doc.json) to import into your API client.
*
* The version of the OpenAPI document: 1.0
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`delete_delete_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteDeleteTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_active_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetActiveTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_get_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGetTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_get_timesheets`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGetTimesheetsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_recent_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetRecentTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_restart_timesheet_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetRestartTimesheetGetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_stop_timesheet_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetStopTimesheetGetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_app_api_timesheet_meta`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchAppApiTimesheetMetaError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_duplicate_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchDuplicateTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_export_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchExportTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_patch_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchPatchTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_restart_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchRestartTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_stop_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchStopTimesheetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`post_post_timesheet`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostPostTimesheetError {
UnknownValue(serde_json::Value),
}
pub async fn delete_delete_timesheet(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteDeleteTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/api/timesheets/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteDeleteTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_active_timesheet(configuration: &configuration::Configuration, ) -> Result<Vec<models::TimesheetCollectionExpanded>, Error<GetActiveTimesheetError>> {
let uri_str = format!("{}/api/timesheets/active", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::TimesheetCollectionExpanded>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::TimesheetCollectionExpanded>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetActiveTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_get_timesheet(configuration: &configuration::Configuration, id: &str) -> Result<models::TimesheetEntity, Error<GetGetTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/api/timesheets/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGetTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_get_timesheets(configuration: &configuration::Configuration, user: Option<&str>, users_left_square_bracket_right_square_bracket: Option<Vec<serde_json::Value>>, customer: Option<&str>, customers_left_square_bracket_right_square_bracket: Option<Vec<serde_json::Value>>, project: Option<&str>, projects_left_square_bracket_right_square_bracket: Option<Vec<serde_json::Value>>, activity: Option<&str>, activities_left_square_bracket_right_square_bracket: Option<Vec<serde_json::Value>>, page: Option<&str>, size: Option<&str>, tags_left_square_bracket_right_square_bracket: Option<Vec<serde_json::Value>>, order_by: Option<&str>, order: Option<&str>, begin: Option<&str>, end: Option<&str>, exported: Option<&str>, active: Option<&str>, billable: Option<&str>, full: Option<&str>, term: Option<&str>, modified_after: Option<&str>) -> Result<Vec<models::TimesheetCollection>, Error<GetGetTimesheetsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_user = user;
let p_users_left_square_bracket_right_square_bracket = users_left_square_bracket_right_square_bracket;
let p_customer = customer;
let p_customers_left_square_bracket_right_square_bracket = customers_left_square_bracket_right_square_bracket;
let p_project = project;
let p_projects_left_square_bracket_right_square_bracket = projects_left_square_bracket_right_square_bracket;
let p_activity = activity;
let p_activities_left_square_bracket_right_square_bracket = activities_left_square_bracket_right_square_bracket;
let p_page = page;
let p_size = size;
let p_tags_left_square_bracket_right_square_bracket = tags_left_square_bracket_right_square_bracket;
let p_order_by = order_by;
let p_order = order;
let p_begin = begin;
let p_end = end;
let p_exported = exported;
let p_active = active;
let p_billable = billable;
let p_full = full;
let p_term = term;
let p_modified_after = modified_after;
let uri_str = format!("{}/api/timesheets", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_user {
req_builder = req_builder.query(&[("user", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_users_left_square_bracket_right_square_bracket {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("users[]".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("users[]", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_customer {
req_builder = req_builder.query(&[("customer", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_customers_left_square_bracket_right_square_bracket {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("customers[]".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("customers[]", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_project {
req_builder = req_builder.query(&[("project", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_projects_left_square_bracket_right_square_bracket {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("projects[]".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("projects[]", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_activity {
req_builder = req_builder.query(&[("activity", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_activities_left_square_bracket_right_square_bracket {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("activities[]".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("activities[]", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_size {
req_builder = req_builder.query(&[("size", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_tags_left_square_bracket_right_square_bracket {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("tags[]".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("tags[]", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_order_by {
req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_order {
req_builder = req_builder.query(&[("order", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_begin {
req_builder = req_builder.query(&[("begin", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_end {
req_builder = req_builder.query(&[("end", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_exported {
req_builder = req_builder.query(&[("exported", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_active {
req_builder = req_builder.query(&[("active", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_billable {
req_builder = req_builder.query(&[("billable", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_full {
req_builder = req_builder.query(&[("full", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_term {
req_builder = req_builder.query(&[("term", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_modified_after {
req_builder = req_builder.query(&[("modified_after", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::TimesheetCollection>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::TimesheetCollection>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGetTimesheetsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_recent_timesheet(configuration: &configuration::Configuration, begin: Option<&str>, size: Option<&str>) -> Result<Vec<models::TimesheetCollectionExpanded>, Error<GetRecentTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_begin = begin;
let p_size = size;
let uri_str = format!("{}/api/timesheets/recent", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_begin {
req_builder = req_builder.query(&[("begin", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_size {
req_builder = req_builder.query(&[("size", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::TimesheetCollectionExpanded>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::TimesheetCollectionExpanded>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetRecentTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_restart_timesheet_get(configuration: &configuration::Configuration, id: &str, get_restart_timesheet_get_request: Option<models::GetRestartTimesheetGetRequest>) -> Result<models::TimesheetEntity, Error<GetRestartTimesheetGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let p_get_restart_timesheet_get_request = get_restart_timesheet_get_request;
let uri_str = format!("{}/api/timesheets/{id}/restart", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_get_restart_timesheet_get_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetRestartTimesheetGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// This route is available via GET and PATCH, as users over and over again run into errors when stopping. Likely caused by a slow JS engine and a fast-click after page reload.
pub async fn get_stop_timesheet_get(configuration: &configuration::Configuration, id: &str) -> Result<models::TimesheetEntity, Error<GetStopTimesheetGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/api/timesheets/{id}/stop", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetStopTimesheetGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn patch_app_api_timesheet_meta(configuration: &configuration::Configuration, id: &str, patch_kimaiplugin_expenses_api_expense_meta_request: Option<models::PatchKimaipluginExpensesApiExpenseMetaRequest>) -> Result<models::TimesheetEntity, Error<PatchAppApiTimesheetMetaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let p_patch_kimaiplugin_expenses_api_expense_meta_request = patch_kimaiplugin_expenses_api_expense_meta_request;
let uri_str = format!("{}/api/timesheets/{id}/meta", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_patch_kimaiplugin_expenses_api_expense_meta_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PatchAppApiTimesheetMetaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn patch_duplicate_timesheet(configuration: &configuration::Configuration, id: &str) -> Result<models::TimesheetEntity, Error<PatchDuplicateTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/api/timesheets/{id}/duplicate", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PatchDuplicateTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn patch_export_timesheet(configuration: &configuration::Configuration, id: &str) -> Result<models::TimesheetEntity, Error<PatchExportTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/api/timesheets/{id}/export", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PatchExportTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Update an existing timesheet record, you can pass all or just a subset of the attributes.
pub async fn patch_patch_timesheet(configuration: &configuration::Configuration, id: &str, timesheet_edit_form: models::TimesheetEditForm) -> Result<models::TimesheetEntity, Error<PatchPatchTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let p_timesheet_edit_form = timesheet_edit_form;
let uri_str = format!("{}/api/timesheets/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_timesheet_edit_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PatchPatchTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn patch_restart_timesheet(configuration: &configuration::Configuration, id: &str, get_restart_timesheet_get_request: Option<models::GetRestartTimesheetGetRequest>) -> Result<models::TimesheetEntity, Error<PatchRestartTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let p_get_restart_timesheet_get_request = get_restart_timesheet_get_request;
let uri_str = format!("{}/api/timesheets/{id}/restart", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_get_restart_timesheet_get_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PatchRestartTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// This route is available via GET and PATCH, as users over and over again run into errors when stopping. Likely caused by a slow JS engine and a fast-click after page reload.
pub async fn patch_stop_timesheet(configuration: &configuration::Configuration, id: &str) -> Result<models::TimesheetEntity, Error<PatchStopTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/api/timesheets/{id}/stop", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PatchStopTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Creates a new timesheet record for the current user and returns it afterwards.
pub async fn post_post_timesheet(configuration: &configuration::Configuration, timesheet_edit_form: models::TimesheetEditForm, full: Option<&str>) -> Result<models::TimesheetEntity, Error<PostPostTimesheetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_timesheet_edit_form = timesheet_edit_form;
let p_full = full;
let uri_str = format!("{}/api/timesheets", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_full {
req_builder = req_builder.query(&[("full", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_timesheet_edit_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TimesheetEntity`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TimesheetEntity`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PostPostTimesheetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}