#![allow(
clippy::too_many_arguments,
clippy::wildcard_imports,
clippy::doc_markdown
)]
use crate::client::AccountClient;
use crate::error::Error;
use crate::generated::routes;
#[allow(unused_imports)]
use crate::generated::types::*;
use crate::pagination::Page;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetProjectTimesheetParams {
pub from: Option<String>,
pub to: Option<String>,
pub person_id: Option<i64>,
pub page: Option<i32>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetRecordingTimesheetParams {
pub from: Option<String>,
pub to: Option<String>,
pub person_id: Option<i64>,
pub page: Option<i32>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetTimesheetReportParams {
pub from: Option<String>,
pub to: Option<String>,
pub person_id: Option<i64>,
}
#[derive(Debug, Clone, Copy)]
pub struct TimesheetsService<'a> {
client: &'a AccountClient,
}
impl<'a> TimesheetsService<'a> {
pub(crate) fn new(client: &'a AccountClient) -> Self {
Self { client }
}
pub fn client(&self) -> &'a AccountClient {
self.client
}
pub async fn create(
&self,
recording_id: i64,
body: &CreateTimesheetEntryRequestContent,
) -> Result<CreateTimesheetEntryResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::CREATE_TIMESHEET_ENTRY, &[&recording_id]);
operation.json(body)?;
self.client.send(operation).await
}
pub async fn destroy(&self, entry_id: i64) -> Result<(), Error> {
let operation = self
.client
.operation(&routes::DESTROY_TIMESHEET_ENTRY, &[&entry_id]);
self.client.send_unit(operation).await
}
pub async fn for_project(
&self,
project_id: i64,
params: &GetProjectTimesheetParams,
) -> Result<Page<GetProjectTimesheetResponseContent>, Error> {
let mut operation = self
.client
.operation(&routes::GET_PROJECT_TIMESHEET, &[&project_id]);
operation.query_optional("from", params.from.as_ref());
operation.query_optional("to", params.to.as_ref());
operation.query_optional("person_id", params.person_id.as_ref());
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn for_recording(
&self,
recording_id: i64,
params: &GetRecordingTimesheetParams,
) -> Result<Page<GetRecordingTimesheetResponseContent>, Error> {
let mut operation = self
.client
.operation(&routes::GET_RECORDING_TIMESHEET, &[&recording_id]);
operation.query_optional("from", params.from.as_ref());
operation.query_optional("to", params.to.as_ref());
operation.query_optional("person_id", params.person_id.as_ref());
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn get(&self, entry_id: i64) -> Result<GetTimesheetEntryResponseContent, Error> {
let operation = self
.client
.operation(&routes::GET_TIMESHEET_ENTRY, &[&entry_id]);
self.client.send(operation).await
}
pub async fn report(
&self,
params: &GetTimesheetReportParams,
) -> Result<GetTimesheetReportResponseContent, Error> {
let mut operation = self.client.operation(&routes::GET_TIMESHEET_REPORT, &[]);
operation.query_optional("from", params.from.as_ref());
operation.query_optional("to", params.to.as_ref());
operation.query_optional("person_id", params.person_id.as_ref());
self.client.send(operation).await
}
pub async fn update(
&self,
entry_id: i64,
body: &UpdateTimesheetEntryRequestContent,
) -> Result<UpdateTimesheetEntryResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::UPDATE_TIMESHEET_ENTRY, &[&entry_id]);
operation.json(body)?;
self.client.send(operation).await
}
}