Skip to main content

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

1//! Update a Microsoft To Do task
2//! (`PATCH /me/todo/lists/{id}/tasks/{id}`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/todotask-update>
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        rest::users::todo::tasks::MsgraphTodoTask,
17        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
18    },
19};
20
21/// Updates a Microsoft To Do task.
22pub struct MsgraphTodoTaskUpdate {
23    send: MsgraphSend<MsgraphTodoTask>,
24}
25
26impl MsgraphTodoTaskUpdate {
27    /// Patches the task `id` of the list `list_id` with the set and null
28    /// fields of `task`; linked resources and checklist items are not
29    /// written this way.
30    pub fn new(
31        auth: &HttpAuthBearer,
32        user_id: &str,
33        list_id: &str,
34        id: &str,
35        task: &MsgraphTodoTask,
36    ) -> Result<Self, MsgraphSendError> {
37        debug!("prepare microsoft graph to do task update");
38        trace!("list: {list_id:?}, id: {id:?}");
39        trace!("task: {task:?}");
40
41        let user = user_path(user_id);
42        let path = format!("{user}/todo/lists/{list_id}/tasks/{id}");
43        let url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
44        let send = MsgraphSend::patch_json(auth, url, task)?;
45
46        Ok(Self { send })
47    }
48}
49
50impl MsgraphCoroutine for MsgraphTodoTaskUpdate {
51    type Yield = MsgraphYield;
52    type Return = Result<MsgraphSendOutput<MsgraphTodoTask>, 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 updated");
57        trace!("out: {out:?}");
58        MsgraphCoroutineState::Complete(Ok(out))
59    }
60}