io_msgraph/v1/rest/users/todo/tasks/
delta.rs1use alloc::{format, string::String, vec::Vec};
15
16use io_http::rfc6750::bearer::HttpAuthBearer;
17use log::{debug, trace};
18use serde::{Deserialize, Serialize};
19use url::Url;
20
21use crate::{
22 coroutine::*,
23 msgraph_try,
24 v1::{
25 rest::users::{contacts::delta::MsgraphRemoved, todo::tasks::MsgraphTodoTask},
26 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
27 },
28};
29
30#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
35pub struct MsgraphTodoTasksDeltaResponse {
36 #[serde(default)]
38 pub value: Vec<MsgraphTodoTaskDelta>,
39 #[serde(default, rename = "@odata.nextLink")]
41 pub next_link: Option<String>,
42 #[serde(default, rename = "@odata.deltaLink")]
44 pub delta_link: Option<String>,
45}
46
47#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
50pub struct MsgraphTodoTaskDelta {
51 #[serde(flatten)]
53 pub task: MsgraphTodoTask,
54 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
56 pub removed: Option<MsgraphRemoved>,
57}
58
59pub struct MsgraphTodoTasksDelta {
63 send: MsgraphSend<MsgraphTodoTasksDeltaResponse>,
64}
65
66impl MsgraphTodoTasksDelta {
67 pub fn new(
72 auth: &HttpAuthBearer,
73 user_id: &str,
74 list_id: &str,
75 select: Option<&str>,
76 ) -> Result<Self, MsgraphSendError> {
77 debug!("prepare microsoft graph to do tasks delta");
78 trace!("list: {list_id:?}, select: {select:?}");
79
80 let user = user_path(user_id);
81 let path = format!("{user}/todo/lists/{list_id}/tasks/delta");
82 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
83 if let Some(select) = select {
84 url.query_pairs_mut().append_pair("$select", select);
85 }
86
87 let send = MsgraphSend::get(auth, url);
88
89 Ok(Self { send })
90 }
91
92 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
95 debug!("prepare microsoft graph to do tasks delta from link");
96 trace!("link: {link}");
97
98 let url = Url::parse(link)?;
99 let send = MsgraphSend::get(auth, url);
100
101 Ok(Self { send })
102 }
103
104 pub fn max_page_size(mut self, size: u32) -> Self {
110 self.send = self.send.max_page_size(size);
111 self
112 }
113}
114
115impl MsgraphCoroutine for MsgraphTodoTasksDelta {
116 type Yield = MsgraphYield;
117 type Return = Result<MsgraphSendOutput<MsgraphTodoTasksDeltaResponse>, MsgraphSendError>;
118
119 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
120 let out = msgraph_try!(&mut self.send, arg);
121 debug!("to do tasks delta page received");
122 trace!("out: {out:?}");
123 MsgraphCoroutineState::Complete(Ok(out))
124 }
125}