use crate::Client;
use anyhow::Result;
#[derive(Clone, Debug)]
pub struct Trash {
pub client: Client,
}
impl Trash {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Self { client }
}
#[doc = "Perform a `GET` request to `/api/trash/`.\n\n**Parameters:**\n\n- `page: Option<i64>`: A page number within the paginated result set.\n- `page_size: Option<i64>`: Number of results to return per page.\n\n```rust,no_run\nasync fn example_trash_list() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n client.trash().list(Some(4 as i64), Some(4 as i64)).await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn list<'a>(
&'a self,
page: Option<i64>,
page_size: Option<i64>,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "api/trash/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
let mut query_params = vec![];
if let Some(p) = page {
query_params.push(("page", format!("{p}")));
}
if let Some(p) = page_size {
query_params.push(("page_size", format!("{p}")));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `POST` request to `/api/trash/`.\n\n```rust,no_run\nasync fn example_trash_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n client\n .trash()\n .create(&paperless_api_client::types::TrashRequest {\n documents: Some(vec![4 as i64]),\n action: paperless_api_client::types::TrashActionEnum::Empty,\n })\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn create<'a>(
&'a self,
body: &crate::types::TrashRequest,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "api/trash/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
}