io_msgraph/v1/rest/users/todo/lists/
list.rs1use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use serde::Serialize;
10use url::Url;
11
12use crate::{
13 coroutine::*,
14 msgraph_try,
15 v1::{
16 page::{MsgraphPage, link_url},
17 query::to_query_pairs,
18 rest::users::todo::lists::MsgraphTodoList,
19 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
20 },
21};
22
23pub type MsgraphTodoListsListResponse = MsgraphPage<MsgraphTodoList>;
25
26#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
28pub struct MsgraphTodoListsListParams<'a> {
29 #[serde(rename = "$top")]
31 pub top: Option<u32>,
32 #[serde(rename = "$skip")]
34 pub skip: Option<u32>,
35 #[serde(rename = "$select")]
37 pub select: Option<&'a str>,
38 #[serde(rename = "$filter")]
40 pub filter: Option<&'a str>,
41}
42
43pub struct MsgraphTodoListsList {
45 send: MsgraphSend<MsgraphTodoListsListResponse>,
46}
47
48impl MsgraphTodoListsList {
49 pub fn new(
51 auth: &HttpAuthBearer,
52 user_id: &str,
53 params: &MsgraphTodoListsListParams,
54 ) -> Result<Self, MsgraphSendError> {
55 debug!("prepare microsoft graph to do lists listing");
56 trace!("params: {params:?}");
57
58 let user = user_path(user_id)?;
59 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/todo/lists"))?;
60 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
61
62 let send = MsgraphSend::get(auth, url);
63
64 Ok(Self { send })
65 }
66
67 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
70 debug!("prepare microsoft graph to do lists listing from link");
71 trace!("link: {link}");
72
73 let url = link_url(link)?;
74 let send = MsgraphSend::get(auth, url);
75
76 Ok(Self { send })
77 }
78}
79
80impl MsgraphCoroutine for MsgraphTodoListsList {
81 type Yield = MsgraphYield;
82 type Return = Result<MsgraphSendOutput<MsgraphTodoListsListResponse>, MsgraphSendError>;
83
84 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
85 let out = msgraph_try!(&mut self.send, arg);
86 debug!("to do lists listed");
87 trace!("out: {out:?}");
88 MsgraphCoroutineState::Complete(Ok(out))
89 }
90}