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::{
18            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
19            user_path,
20        },
21    },
22};
23
24/// Updates a Microsoft To Do task.
25pub struct MsgraphTodoTaskUpdate {
26    send: MsgraphSend<MsgraphTodoTask>,
27}
28
29impl MsgraphTodoTaskUpdate {
30    /// Patches the task `id` of the list `list_id` with the set and null
31    /// fields of `task`; linked resources and checklist items are not
32    /// written this way.
33    pub fn new(
34        auth: &HttpAuthBearer,
35        user_id: &str,
36        list_id: &str,
37        id: &str,
38        task: &MsgraphTodoTask,
39    ) -> Result<Self, MsgraphSendError> {
40        debug!("prepare microsoft graph to do task update");
41        trace!("list: {list_id:?}, id: {id:?}");
42        trace!("task: {task:?}");
43
44        let user = user_path(user_id)?;
45        let path = format!(
46            "{user}/todo/lists/{}/tasks/{}",
47            path_segment(list_id)?,
48            path_segment(id)?
49        );
50        let url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
51        let send = MsgraphSend::patch_json(auth, url, task)?;
52
53        Ok(Self { send })
54    }
55}
56
57impl MsgraphCoroutine for MsgraphTodoTaskUpdate {
58    type Yield = MsgraphYield;
59    type Return = Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphSendError>;
60
61    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
62        let out = msgraph_try!(&mut self.send, arg);
63        debug!("to do task updated");
64        trace!("out: {out:?}");
65        MsgraphCoroutineState::Complete(Ok(out))
66    }
67}