basecamp-sdk 0.18.0

Official Basecamp API client, generated from the Smithy model in spec/
Documentation
// Generated by basecamp-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

//! Timesheets operations.

#![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;

/// Optional query parameters for `GetProjectTimesheet`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetProjectTimesheetParams {
    /// `from`.
    pub from: Option<String>,
    /// `to`.
    pub to: Option<String>,
    /// `person_id`.
    pub person_id: Option<i64>,
    /// Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.
    pub page: Option<i32>,
}

/// Optional query parameters for `GetRecordingTimesheet`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetRecordingTimesheetParams {
    /// `from`.
    pub from: Option<String>,
    /// `to`.
    pub to: Option<String>,
    /// `person_id`.
    pub person_id: Option<i64>,
    /// Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.
    pub page: Option<i32>,
}

/// Optional query parameters for `GetTimesheetReport`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetTimesheetReportParams {
    /// `from`.
    pub from: Option<String>,
    /// `to`.
    pub to: Option<String>,
    /// `person_id`.
    pub person_id: Option<i64>,
}

/// `Timesheets` operations, sent through one [`AccountClient`].
#[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 }
    }

    /// The client this service sends through.
    pub fn client(&self) -> &'a AccountClient {
        self.client
    }

    /// Create a timesheet entry on a recording
    ///
    /// `POST /recordings/{recordingId}/timesheet/entries.json` — not idempotent, sent exactly once.
    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
    }

    /// Permanently delete a timesheet entry; answers 403 when the caller may not archive or trash it.
    ///
    /// `DELETE /timesheet_entries/{entryId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    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
    }

    /// Get timesheet for a specific project
    ///
    /// `GET /projects/{projectId}/timesheet.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    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
    }

    /// Get timesheet for a specific recording
    ///
    /// `GET /recordings/{recordingId}/timesheet.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    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
    }

    /// Get a single timesheet entry
    ///
    /// `GET /timesheet_entries/{entryId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    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
    }

    /// Get account-wide timesheet report
    ///
    /// `GET /reports/timesheet.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    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
    }

    /// Update a timesheet entry
    ///
    /// `PUT /timesheet_entries/{entryId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    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
    }
}