io_msgraph/v1/rest/users/todo/lists/
delta.rs1use alloc::format;
12
13use io_http::rfc6750::bearer::HttpAuthBearer;
14use log::{debug, trace};
15use serde::{Deserialize, Serialize};
16use url::Url;
17
18use crate::{
19 coroutine::*,
20 msgraph_try,
21 v1::{
22 page::{MsgraphPage, link_url},
23 rest::users::{contacts::delta::MsgraphRemoved, todo::lists::MsgraphTodoList},
24 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
25 },
26};
27
28pub type MsgraphTodoListsDeltaResponse = MsgraphPage<MsgraphTodoListDelta>;
33
34#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
37pub struct MsgraphTodoListDelta {
38 #[serde(flatten)]
40 pub list: MsgraphTodoList,
41 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
43 pub removed: Option<MsgraphRemoved>,
44}
45
46pub struct MsgraphTodoListsDelta {
50 send: MsgraphSend<MsgraphTodoListsDeltaResponse>,
51}
52
53impl MsgraphTodoListsDelta {
54 pub fn new(auth: &HttpAuthBearer, user_id: &str) -> Result<Self, MsgraphSendError> {
56 debug!("prepare microsoft graph to do lists delta");
57
58 let user = user_path(user_id)?;
59 let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/todo/lists/delta"))?;
60 let send = MsgraphSend::get(auth, url);
61
62 Ok(Self { send })
63 }
64
65 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
69 debug!("prepare microsoft graph to do lists delta from link");
70 trace!("link: {link}");
71
72 let url = link_url(link)?;
73 let send = MsgraphSend::get(auth, url);
74
75 Ok(Self { send })
76 }
77
78 pub fn max_page_size(mut self, size: u32) -> Self {
84 self.send = self.send.max_page_size(size);
85 self
86 }
87}
88
89impl MsgraphCoroutine for MsgraphTodoListsDelta {
90 type Yield = MsgraphYield;
91 type Return = Result<MsgraphSendOutput<MsgraphTodoListsDeltaResponse>, MsgraphSendError>;
92
93 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
94 let out = msgraph_try!(&mut self.send, arg);
95 debug!("to do lists delta page received");
96 trace!("out: {out:?}");
97 MsgraphCoroutineState::Complete(Ok(out))
98 }
99}