Skip to main content

io_msgraph/v1/rest/users/calendars/
permanent_delete.rs

1//! Permanently delete a Microsoft Graph calendar
2//! (`POST /me/calendars/{id}/permanentDelete`).
3//!
4//! A plain delete moves the calendar to Deleted Items, where it stays until
5//! that folder is emptied; this one removes it to the Recoverable Items
6//! folder at once.
7//!
8//! <https://learn.microsoft.com/en-us/graph/api/calendar-permanentdelete>
9
10use alloc::format;
11
12use io_http::rfc6750::bearer::HttpAuthBearer;
13use log::{debug, trace};
14use url::Url;
15
16use crate::{
17    coroutine::*,
18    msgraph_try,
19    v1::send::{
20        MSGRAPH_API_BASE, MsgraphNoResponse, MsgraphSend, MsgraphSendError, MsgraphSendOutput,
21        path_segment, user_path,
22    },
23};
24
25/// Permanently deletes a Microsoft Graph calendar.
26pub struct MsgraphCalendarPermanentDelete {
27    send: MsgraphSend<MsgraphNoResponse>,
28}
29
30impl MsgraphCalendarPermanentDelete {
31    /// Permanently deletes the calendar `id`.
32    pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, MsgraphSendError> {
33        debug!("prepare microsoft graph calendar permanent deletion");
34        trace!("id: {id:?}");
35
36        let user = user_path(user_id)?;
37        let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!(
38            "{user}/calendars/{}/permanentDelete",
39            path_segment(id)?
40        ))?;
41        let body = b"{}".to_vec();
42        let send = MsgraphSend::with_method(auth, "POST", url, Some("application/json"), body);
43
44        Ok(Self { send })
45    }
46}
47
48impl MsgraphCoroutine for MsgraphCalendarPermanentDelete {
49    type Yield = MsgraphYield;
50    type Return = Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphSendError>;
51
52    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
53        let out = msgraph_try!(&mut self.send, arg);
54        debug!("calendar permanently deleted");
55        trace!("out: {out:?}");
56        MsgraphCoroutineState::Complete(Ok(out))
57    }
58}