Skip to main content

hey_sdk/generated/services/
journal.rs

1// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
2
3#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
4
5use crate::client::Client;
6use crate::error::Error;
7use crate::generated::routes;
8use crate::generated::types::*;
9use crate::pagination::Page;
10
11/// Optional query parameters for `ListJournalEntries`.
12#[derive(Debug, Clone, Default, PartialEq)]
13pub struct ListJournalEntriesParams {
14    pub page: Option<String>,
15    pub q: Option<String>,
16}
17
18pub struct Journal<'a> {
19    client: &'a Client,
20}
21
22impl<'a> Journal<'a> {
23    pub(crate) fn new(client: &'a Client) -> Self {
24        Self { client }
25    }
26
27    /// The client this service sends through.
28    pub fn client(&self) -> &'a Client {
29        self.client
30    }
31
32    /// Get journal entry for a day
33    pub async fn get_entry(&self, day: &str) -> Result<GetJournalEntryResponseContent, Error> {
34        let operation = self.client.operation(&routes::GET_JOURNAL_ENTRY, &[&day]);
35        self.client.send(operation).await
36    }
37
38    /// List journal entries newest first. The next page, if any, is a Link header.
39    /// Pass q to search journal entry content.
40    pub async fn list_entries(
41        &self,
42        params: &ListJournalEntriesParams,
43    ) -> Result<Page<ListJournalEntriesResponseContent>, Error> {
44        let mut operation = self.client.operation(&routes::LIST_JOURNAL_ENTRIES, &[]);
45        operation.query_optional("page", params.page.as_ref());
46        operation.query_optional("q", params.q.as_ref());
47        self.client.send_page(operation).await
48    }
49
50    /// Update the journal entry for a day: writes it, creating it if the day has none, and
51    /// answers the entry as a recording. Empty content removes the entry instead, and HEY then
52    /// answers 204 with no body — which is not this shape, so send that through the SDK's own
53    /// journal wrapper rather than here.
54    pub async fn update_entry(
55        &self,
56        day: &str,
57        body: &UpdateJournalEntryRequestContent,
58    ) -> Result<UpdateJournalEntryResponseContent, Error> {
59        let mut operation = self
60            .client
61            .operation(&routes::UPDATE_JOURNAL_ENTRY, &[&day]);
62        operation.json(body)?;
63        self.client.send(operation).await
64    }
65}