Skip to main content

io_msgraph/v1/rest/users/todo/tasks/
delete.rs

1//! Delete a Microsoft To Do task
2//! (`DELETE /me/todo/lists/{id}/tasks/{id}`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/todotask-delete>
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::send::{
16        MSGRAPH_API_BASE, MsgraphNoResponse, MsgraphSend, MsgraphSendError, MsgraphSendOutput,
17        path_segment, user_path,
18    },
19};
20
21/// Deletes a Microsoft To Do task.
22pub struct MsgraphTodoTaskDelete {
23    send: MsgraphSend<MsgraphNoResponse>,
24}
25
26impl MsgraphTodoTaskDelete {
27    /// Deletes the task `id` of the list `list_id`.
28    pub fn new(
29        auth: &HttpAuthBearer,
30        user_id: &str,
31        list_id: &str,
32        id: &str,
33    ) -> Result<Self, MsgraphSendError> {
34        debug!("prepare microsoft graph to do task deletion");
35        trace!("list: {list_id:?}, id: {id:?}");
36
37        let user = user_path(user_id)?;
38        let path = format!(
39            "{user}/todo/lists/{}/tasks/{}",
40            path_segment(list_id)?,
41            path_segment(id)?
42        );
43        let url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
44        let send = MsgraphSend::delete(auth, url);
45
46        Ok(Self { send })
47    }
48}
49
50impl MsgraphCoroutine for MsgraphTodoTaskDelete {
51    type Yield = MsgraphYield;
52    type Return = Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphSendError>;
53
54    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
55        let out = msgraph_try!(&mut self.send, arg);
56        debug!("to do task deleted");
57        trace!("out: {out:?}");
58        MsgraphCoroutineState::Complete(Ok(out))
59    }
60}