basecamp-sdk 0.38.0

Official client for Basecamp - https://basecamp.com
Documentation
// Generated by basecamp-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

//! Subtasks 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 `ListSubtasks`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListSubtasksParams {
    /// 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>,
}

/// `Subtasks` operations, sent through one [`AccountClient`].
#[derive(Debug, Clone, Copy)]
pub struct SubtasksService<'a> {
    client: &'a AccountClient,
}

impl<'a> SubtasksService<'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
    }

    /// Mark a subtask as completed
    ///
    /// `POST /subtasks/{subtaskId}/completion.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn complete(&self, subtask_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::COMPLETE_SUBTASK, &[&subtask_id]);
        self.client.send_unit(operation).await
    }

    /// Create a subtask under a to-do or a card
    ///
    /// Any other recording answers `403 Forbidden`.
    ///
    /// `POST /recordings/{recordingId}/subtasks.json` — not idempotent, sent exactly once.
    pub async fn create(
        &self,
        recording_id: i64,
        body: &CreateSubtaskRequestContent,
    ) -> Result<CreateSubtaskResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_SUBTASK, &[&recording_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Delete a subtask
    ///
    /// On accounts where deleting is limited to admins and the creator, everyone
    /// else gets `403 Forbidden`.
    ///
    /// `DELETE /subtasks/{subtaskId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete(&self, subtask_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::DELETE_SUBTASK, &[&subtask_id]);
        self.client.send_unit(operation).await
    }

    /// Get a subtask by ID
    ///
    /// `GET /subtasks/{subtaskId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, subtask_id: i64) -> Result<GetSubtaskResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_SUBTASK, &[&subtask_id]);
        self.client.send(operation).await
    }

    /// List a recording's subtasks, in position order
    ///
    /// Only to-dos and cards hold subtasks; check for `subtasks_count` and
    /// `subtasks_url` on the parent's JSON.
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /recordings/{recordingId}/subtasks.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(
        &self,
        recording_id: i64,
        params: &ListSubtasksParams,
    ) -> Result<Page<ListSubtasksResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_SUBTASKS, &[&recording_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Move a subtask to a new position among its siblings
    ///
    /// `PUT /subtasks/{subtaskId}/position.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn reposition(
        &self,
        subtask_id: i64,
        body: &RepositionSubtaskRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::REPOSITION_SUBTASK, &[&subtask_id]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Mark a subtask as not completed
    ///
    /// `DELETE /subtasks/{subtaskId}/completion.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn uncomplete(&self, subtask_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::UNCOMPLETE_SUBTASK, &[&subtask_id]);
        self.client.send_unit(operation).await
    }

    /// Update a subtask
    ///
    /// A partial update: every omitted parameter is left unchanged. Clearing a
    /// value takes an explicit send — `"due_on": null` clears the due date (an
    /// empty string is accepted too, and is what the Ruby, Python and TypeScript
    /// SDKs send, since they drop nil, None and undefined from the body);
    /// `"assignee_ids": \[\]` removes every assignee. Send at least one parameter:
    /// an empty body is refused with `400 Bad Request`.
    ///
    /// `PUT /subtasks/{subtaskId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        subtask_id: i64,
        body: &UpdateSubtaskRequestContent,
    ) -> Result<UpdateSubtaskResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_SUBTASK, &[&subtask_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}