Skip to main content

io_msgraph/v1/rest/users/contact_folders/
child_folders.rs

1//! List the child folders of a Microsoft Graph contact folder
2//! (`GET /me/contactFolders/{id}/childFolders`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/contactfolder-list-childfolders>
5
6use alloc::format;
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use url::Url;
11
12use crate::{
13    coroutine::*,
14    msgraph_try,
15    v1::{
16        query::to_query_pairs,
17        rest::users::contact_folders::list::{
18            MsgraphContactFoldersListParams, MsgraphContactFoldersListResponse,
19        },
20        send::{
21            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
22            user_path,
23        },
24    },
25};
26
27/// Lists the child folders of a Microsoft Graph contact folder.
28pub struct MsgraphContactChildFoldersList {
29    send: MsgraphSend<MsgraphContactFoldersListResponse>,
30}
31
32impl MsgraphContactChildFoldersList {
33    /// Lists the child folders of the contact folder `id`, filtered by
34    /// the OData `params`.
35    pub fn new(
36        auth: &HttpAuthBearer,
37        user_id: &str,
38        id: &str,
39        params: &MsgraphContactFoldersListParams,
40    ) -> Result<Self, MsgraphSendError> {
41        debug!("prepare microsoft graph contact child folders listing");
42        trace!("id: {id:?}");
43        trace!("params: {params:?}");
44
45        let user = user_path(user_id)?;
46        let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!(
47            "{user}/contactFolders/{}/childFolders",
48            path_segment(id)?
49        ))?;
50        url.query_pairs_mut().extend_pairs(to_query_pairs(params));
51
52        let send = MsgraphSend::get(auth, url);
53
54        Ok(Self { send })
55    }
56}
57
58impl MsgraphCoroutine for MsgraphContactChildFoldersList {
59    type Yield = MsgraphYield;
60    type Return = Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphSendError>;
61
62    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
63        let out = msgraph_try!(&mut self.send, arg);
64        debug!("contact child folders listed");
65        trace!("out: {out:?}");
66        MsgraphCoroutineState::Complete(Ok(out))
67    }
68}