io_msgraph/v1/rest/users/todo/tasks/
list.rs1use alloc::format;
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use serde::Serialize;
11use url::Url;
12
13use crate::{
14 coroutine::*,
15 msgraph_try,
16 v1::{
17 page::{MsgraphPage, link_url},
18 query::to_query_pairs,
19 rest::users::todo::tasks::MsgraphTodoTask,
20 send::{
21 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
22 user_path,
23 },
24 },
25};
26
27pub type MsgraphTodoTasksListResponse = MsgraphPage<MsgraphTodoTask>;
29
30#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
32pub struct MsgraphTodoTasksListParams<'a> {
33 #[serde(rename = "$top")]
35 pub top: Option<u32>,
36 #[serde(rename = "$skip")]
38 pub skip: Option<u32>,
39 #[serde(rename = "$select")]
41 pub select: Option<&'a str>,
42 #[serde(rename = "$filter")]
44 pub filter: Option<&'a str>,
45 #[serde(rename = "$orderby")]
47 pub orderby: Option<&'a str>,
48 #[serde(rename = "$expand")]
50 pub expand: Option<&'a str>,
51}
52
53pub struct MsgraphTodoTasksList {
55 send: MsgraphSend<MsgraphTodoTasksListResponse>,
56}
57
58impl MsgraphTodoTasksList {
59 pub fn new(
61 auth: &HttpAuthBearer,
62 user_id: &str,
63 list_id: &str,
64 params: &MsgraphTodoTasksListParams,
65 ) -> Result<Self, MsgraphSendError> {
66 debug!("prepare microsoft graph to do tasks listing");
67 trace!("list: {list_id:?}");
68 trace!("params: {params:?}");
69
70 let user = user_path(user_id)?;
71 let path = format!("{user}/todo/lists/{}/tasks", path_segment(list_id)?);
72 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
73 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
74
75 let send = MsgraphSend::get(auth, url);
76
77 Ok(Self { send })
78 }
79
80 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
83 debug!("prepare microsoft graph to do tasks listing from link");
84 trace!("link: {link}");
85
86 let url = link_url(link)?;
87 let send = MsgraphSend::get(auth, url);
88
89 Ok(Self { send })
90 }
91
92 pub fn max_page_size(mut self, size: u32) -> Self {
98 self.send = self.send.max_page_size(size);
99 self
100 }
101}
102
103impl MsgraphCoroutine for MsgraphTodoTasksList {
104 type Yield = MsgraphYield;
105 type Return = Result<MsgraphSendOutput<MsgraphTodoTasksListResponse>, MsgraphSendError>;
106
107 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
108 let out = msgraph_try!(&mut self.send, arg);
109 debug!("to do tasks listed");
110 trace!("out: {out:?}");
111 MsgraphCoroutineState::Complete(Ok(out))
112 }
113}