Skip to main content

io_msgraph/v1/rest/users/todo/lists/
list.rs

1//! List Microsoft To Do task lists (`GET /me/todo/lists`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/todo-list-lists>
4
5use alloc::{format, string::String, vec::Vec};
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use serde::{Deserialize, Serialize};
10use url::Url;
11
12use crate::{
13    coroutine::*,
14    msgraph_try,
15    v1::{
16        query::to_query_pairs,
17        rest::users::todo::lists::MsgraphTodoList,
18        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
19    },
20};
21
22/// One page of task lists (`value` plus the OData paging link).
23#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
24pub struct MsgraphTodoListsListResponse {
25    /// The task lists of the page.
26    #[serde(default)]
27    pub value: Vec<MsgraphTodoList>,
28    /// The URL of the next page, when one exists.
29    #[serde(default, rename = "@odata.nextLink")]
30    pub next_link: Option<String>,
31}
32
33/// OData query parameters for listing task lists.
34#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
35pub struct MsgraphTodoListsListParams<'a> {
36    /// Maximum number of lists per page (`$top`).
37    #[serde(rename = "$top")]
38    pub top: Option<u32>,
39    /// Number of lists to skip (`$skip`).
40    #[serde(rename = "$skip")]
41    pub skip: Option<u32>,
42    /// Comma-separated properties to return (`$select`).
43    #[serde(rename = "$select")]
44    pub select: Option<&'a str>,
45    /// OData filter expression (`$filter`).
46    #[serde(rename = "$filter")]
47    pub filter: Option<&'a str>,
48}
49
50/// Lists the Microsoft To Do task lists of the user.
51pub struct MsgraphTodoListsList {
52    send: MsgraphSend<MsgraphTodoListsListResponse>,
53}
54
55impl MsgraphTodoListsList {
56    /// Lists the user's task lists.
57    pub fn new(
58        auth: &HttpAuthBearer,
59        user_id: &str,
60        params: &MsgraphTodoListsListParams,
61    ) -> Result<Self, MsgraphSendError> {
62        debug!("prepare microsoft graph to do lists listing");
63        trace!("params: {params:?}");
64
65        let user = user_path(user_id);
66        let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/todo/lists"))?;
67        url.query_pairs_mut().extend_pairs(to_query_pairs(params));
68
69        let send = MsgraphSend::get(auth, url);
70
71        Ok(Self { send })
72    }
73
74    /// Continues a listing from an `@odata.nextLink`, sent as-is.
75    pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
76        debug!("prepare microsoft graph to do lists listing from link");
77        trace!("link: {link}");
78
79        let url = Url::parse(link)?;
80        let send = MsgraphSend::get(auth, url);
81
82        Ok(Self { send })
83    }
84}
85
86impl MsgraphCoroutine for MsgraphTodoListsList {
87    type Yield = MsgraphYield;
88    type Return = Result<MsgraphSendOutput<MsgraphTodoListsListResponse>, MsgraphSendError>;
89
90    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
91        let out = msgraph_try!(&mut self.send, arg);
92        debug!("to do lists listed");
93        trace!("out: {out:?}");
94        MsgraphCoroutineState::Complete(Ok(out))
95    }
96}