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.

//! Todos 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 `ListTodos`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListTodosParams {
    /// active|archived|trashed
    pub status: Option<String>,
    /// `completed`.
    pub completed: Option<bool>,
    /// 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>,
}

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

impl<'a> TodosService<'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 todo as complete
    ///
    /// `POST /todos/{todoId}/completion.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn complete(&self, todo_id: i64) -> Result<(), Error> {
        let operation = self.client.operation(&routes::COMPLETE_TODO, &[&todo_id]);
        self.client.send_unit(operation).await
    }

    /// Create a new todo in a todolist
    ///
    /// `POST /todolists/{todolistId}/todos.json` — not idempotent, sent exactly once.
    pub async fn create(
        &self,
        todolist_id: i64,
        body: &CreateTodoRequestContent,
    ) -> Result<CreateTodoResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_TODO, &[&todolist_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create a to-do directly under a project's to-do set, outside any to-do list.
    /// This form exists only project-scoped (no account-scoped variant); parameters
    /// and response match the to-do-list create. Find a project's to-do set id via
    /// GetTodoset.
    ///
    /// `POST /buckets/{bucketId}/todosets/{todosetId}/todos.json` — not idempotent, sent exactly once.
    pub async fn create_todoset_todo(
        &self,
        bucket_id: i64,
        todoset_id: i64,
        body: &CreateTodosetTodoRequestContent,
    ) -> Result<CreateTodosetTodoResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_TODOSET_TODO, &[&bucket_id, &todoset_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Get a single todo by id
    ///
    /// `GET /todos/{todoId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, todo_id: i64) -> Result<GetTodoResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_TODO, &[&todo_id]);
        self.client.send(operation).await
    }

    /// List todos in a todolist
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /todolists/{todolistId}/todos.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(
        &self,
        todolist_id: i64,
        params: &ListTodosParams,
    ) -> Result<Page<ListTodosResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_TODOS, &[&todolist_id]);
        operation.query_optional("status", params.status.as_ref());
        operation.query_optional("completed", params.completed.as_ref());
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Replace a todo with a new complete representation.
    /// The request body is the todo's full writable state: any writable field
    /// omitted from the request is cleared server-side (empty/missing
    /// assignee_ids clears assignees, missing description clears it, and so
    /// on). content is required — a request without it is rejected.
    /// To set some fields while preserving the rest, use the SDK's merge-safe
    /// update or edit methods, which GET the current todo and PUT the full
    /// representation back. Those read-modify-write helpers are not atomic:
    /// a concurrent write between the GET and PUT is overwritten (last write
    /// wins for the whole representation; the window is one round-trip).
    ///
    /// `PUT /todos/{todoId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn replace(
        &self,
        todo_id: i64,
        body: &ReplaceTodoRequestContent,
    ) -> Result<ReplaceTodoResponseContent, Error> {
        let mut operation = self.client.operation(&routes::REPLACE_TODO, &[&todo_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Reposition a todo within its todolist, or move it into another list or the to-do set in the same project.
    ///
    /// `parent_id` names a to-do list, or the project's to-do set, to move the todo
    /// into; the todo keeps its id. It must be in the same project: anything else
    /// answers 422. To move a todo into a list in another project, use
    /// MoveRecording.
    ///
    /// `PUT /todos/{todoId}/position.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn reposition(
        &self,
        todo_id: i64,
        body: &RepositionTodoRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::REPOSITION_TODO, &[&todo_id]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Mark a todo as incomplete
    ///
    /// `DELETE /todos/{todoId}/completion.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn uncomplete(&self, todo_id: i64) -> Result<(), Error> {
        let operation = self.client.operation(&routes::UNCOMPLETE_TODO, &[&todo_id]);
        self.client.send_unit(operation).await
    }
}