jacquard_api/sh_weaver/notebook/
get_chapter.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::AtUri;
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::sh_weaver::notebook::ChapterEntryView;
18use crate::sh_weaver::notebook::ChapterView;
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase")]
22pub struct GetChapter<'a> {
23 #[serde(borrow)]
24 pub chapter: AtUri<'a>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 #[serde(borrow)]
27 pub entry_cursor: Option<CowStr<'a>>,
28 #[serde(default = "_default_entry_limit")]
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub entry_limit: Option<i64>,
32}
33
34
35#[lexicon]
36#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
37#[serde(rename_all = "camelCase")]
38pub struct GetChapterOutput<'a> {
39 #[serde(borrow)]
40 pub chapter: ChapterView<'a>,
41 #[serde(borrow)]
42 pub entries: Vec<ChapterEntryView<'a>>,
43 #[serde(skip_serializing_if = "Option::is_none")]
44 #[serde(borrow)]
45 pub entry_cursor: Option<CowStr<'a>>,
46}
47
48
49#[open_union]
50#[derive(
51 Serialize,
52 Deserialize,
53 Debug,
54 Clone,
55 PartialEq,
56 Eq,
57 thiserror::Error,
58 miette::Diagnostic,
59 IntoStatic
60)]
61
62#[serde(tag = "error", content = "message")]
63#[serde(bound(deserialize = "'de: 'a"))]
64pub enum GetChapterError<'a> {
65 #[serde(rename = "ChapterNotFound")]
66 ChapterNotFound(Option<CowStr<'a>>),
67}
68
69impl core::fmt::Display for GetChapterError<'_> {
70 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 match self {
72 Self::ChapterNotFound(msg) => {
73 write!(f, "ChapterNotFound")?;
74 if let Some(msg) = msg {
75 write!(f, ": {}", msg)?;
76 }
77 Ok(())
78 }
79 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
80 }
81 }
82}
83
84pub struct GetChapterResponse;
86impl jacquard_common::xrpc::XrpcResp for GetChapterResponse {
87 const NSID: &'static str = "sh.weaver.notebook.getChapter";
88 const ENCODING: &'static str = "application/json";
89 type Output<'de> = GetChapterOutput<'de>;
90 type Err<'de> = GetChapterError<'de>;
91}
92
93impl<'a> jacquard_common::xrpc::XrpcRequest for GetChapter<'a> {
94 const NSID: &'static str = "sh.weaver.notebook.getChapter";
95 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
96 type Response = GetChapterResponse;
97}
98
99pub struct GetChapterRequest;
101impl jacquard_common::xrpc::XrpcEndpoint for GetChapterRequest {
102 const PATH: &'static str = "/xrpc/sh.weaver.notebook.getChapter";
103 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
104 type Request<'de> = GetChapter<'de>;
105 type Response = GetChapterResponse;
106}
107
108fn _default_entry_limit() -> Option<i64> {
109 Some(50i64)
110}
111
112pub mod get_chapter_state {
113
114 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
115 #[allow(unused)]
116 use ::core::marker::PhantomData;
117 mod sealed {
118 pub trait Sealed {}
119 }
120 pub trait State: sealed::Sealed {
122 type Chapter;
123 }
124 pub struct Empty(());
126 impl sealed::Sealed for Empty {}
127 impl State for Empty {
128 type Chapter = Unset;
129 }
130 pub struct SetChapter<S: State = Empty>(PhantomData<fn() -> S>);
132 impl<S: State> sealed::Sealed for SetChapter<S> {}
133 impl<S: State> State for SetChapter<S> {
134 type Chapter = Set<members::chapter>;
135 }
136 #[allow(non_camel_case_types)]
138 pub mod members {
139 pub struct chapter(());
141 }
142}
143
144pub struct GetChapterBuilder<'a, S: get_chapter_state::State> {
146 _state: PhantomData<fn() -> S>,
147 _fields: (Option<AtUri<'a>>, Option<CowStr<'a>>, Option<i64>),
148 _lifetime: PhantomData<&'a ()>,
149}
150
151impl<'a> GetChapter<'a> {
152 pub fn new() -> GetChapterBuilder<'a, get_chapter_state::Empty> {
154 GetChapterBuilder::new()
155 }
156}
157
158impl<'a> GetChapterBuilder<'a, get_chapter_state::Empty> {
159 pub fn new() -> Self {
161 GetChapterBuilder {
162 _state: PhantomData,
163 _fields: (None, None, None),
164 _lifetime: PhantomData,
165 }
166 }
167}
168
169impl<'a, S> GetChapterBuilder<'a, S>
170where
171 S: get_chapter_state::State,
172 S::Chapter: get_chapter_state::IsUnset,
173{
174 pub fn chapter(
176 mut self,
177 value: impl Into<AtUri<'a>>,
178 ) -> GetChapterBuilder<'a, get_chapter_state::SetChapter<S>> {
179 self._fields.0 = Option::Some(value.into());
180 GetChapterBuilder {
181 _state: PhantomData,
182 _fields: self._fields,
183 _lifetime: PhantomData,
184 }
185 }
186}
187
188impl<'a, S: get_chapter_state::State> GetChapterBuilder<'a, S> {
189 pub fn entry_cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
191 self._fields.1 = value.into();
192 self
193 }
194 pub fn maybe_entry_cursor(mut self, value: Option<CowStr<'a>>) -> Self {
196 self._fields.1 = value;
197 self
198 }
199}
200
201impl<'a, S: get_chapter_state::State> GetChapterBuilder<'a, S> {
202 pub fn entry_limit(mut self, value: impl Into<Option<i64>>) -> Self {
204 self._fields.2 = value.into();
205 self
206 }
207 pub fn maybe_entry_limit(mut self, value: Option<i64>) -> Self {
209 self._fields.2 = value;
210 self
211 }
212}
213
214impl<'a, S> GetChapterBuilder<'a, S>
215where
216 S: get_chapter_state::State,
217 S::Chapter: get_chapter_state::IsSet,
218{
219 pub fn build(self) -> GetChapter<'a> {
221 GetChapter {
222 chapter: self._fields.0.unwrap(),
223 entry_cursor: self._fields.1,
224 entry_limit: self._fields.2,
225 }
226 }
227}