#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListJournalEntriesParams {
pub page: Option<String>,
pub q: Option<String>,
}
pub struct Journal<'a> {
client: &'a Client,
}
impl<'a> Journal<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub fn client(&self) -> &'a Client {
self.client
}
pub async fn get_entry(&self, day: &str) -> Result<GetJournalEntryResponseContent, Error> {
let operation = self.client.operation(&routes::GET_JOURNAL_ENTRY, &[&day]);
self.client.send(operation).await
}
pub async fn list_entries(
&self,
params: &ListJournalEntriesParams,
) -> Result<Page<ListJournalEntriesResponseContent>, Error> {
let mut operation = self.client.operation(&routes::LIST_JOURNAL_ENTRIES, &[]);
operation.query_optional("page", params.page.as_ref());
operation.query_optional("q", params.q.as_ref());
self.client.send_page(operation).await
}
pub async fn update_entry(
&self,
day: &str,
body: &UpdateJournalEntryRequestContent,
) -> Result<UpdateJournalEntryResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::UPDATE_JOURNAL_ENTRY, &[&day]);
operation.json(body)?;
self.client.send(operation).await
}
}