io_msgraph/v1/rest/users/calendars/
list.rs1use 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::calendars::MsgraphCalendar,
18 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
19 },
20};
21
22#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
24pub struct MsgraphCalendarsListResponse {
25 #[serde(default)]
27 pub value: Vec<MsgraphCalendar>,
28 #[serde(default, rename = "@odata.nextLink")]
30 pub next_link: Option<String>,
31}
32
33#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
35pub struct MsgraphCalendarsListParams<'a> {
36 #[serde(rename = "$top")]
38 pub top: Option<u32>,
39 #[serde(rename = "$skip")]
41 pub skip: Option<u32>,
42 #[serde(rename = "$select")]
44 pub select: Option<&'a str>,
45 #[serde(rename = "$filter")]
47 pub filter: Option<&'a str>,
48}
49
50pub struct MsgraphCalendarsList {
52 send: MsgraphSend<MsgraphCalendarsListResponse>,
53}
54
55impl MsgraphCalendarsList {
56 pub fn new(
58 auth: &HttpAuthBearer,
59 user_id: &str,
60 params: &MsgraphCalendarsListParams,
61 ) -> Result<Self, MsgraphSendError> {
62 debug!("prepare microsoft graph calendars 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}/calendars"))?;
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
75impl MsgraphCoroutine for MsgraphCalendarsList {
76 type Yield = MsgraphYield;
77 type Return = Result<MsgraphSendOutput<MsgraphCalendarsListResponse>, MsgraphSendError>;
78
79 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
80 let out = msgraph_try!(&mut self.send, arg);
81 debug!("calendars listed");
82 trace!("out: {out:?}");
83 MsgraphCoroutineState::Complete(Ok(out))
84 }
85}