Skip to main content

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

1//! Update a Microsoft To Do task list (`PATCH /me/todo/lists/{id}`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/todotasklist-update>
4
5use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12    coroutine::*,
13    msgraph_try,
14    v1::{
15        rest::users::todo::lists::MsgraphTodoList,
16        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
17    },
18};
19
20/// Updates a Microsoft To Do task list.
21pub struct MsgraphTodoListUpdate {
22    send: MsgraphSend<MsgraphTodoList>,
23}
24
25impl MsgraphTodoListUpdate {
26    /// Patches the task list `id` with the set and null fields of `list`.
27    pub fn new(
28        auth: &HttpAuthBearer,
29        user_id: &str,
30        id: &str,
31        list: &MsgraphTodoList,
32    ) -> Result<Self, MsgraphSendError> {
33        debug!("prepare microsoft graph to do list update");
34        trace!("id: {id:?}");
35        trace!("list: {list:?}");
36
37        let user = user_path(user_id);
38        let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/todo/lists/{id}"))?;
39        let send = MsgraphSend::patch_json(auth, url, list)?;
40
41        Ok(Self { send })
42    }
43}
44
45impl MsgraphCoroutine for MsgraphTodoListUpdate {
46    type Yield = MsgraphYield;
47    type Return = Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphSendError>;
48
49    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
50        let out = msgraph_try!(&mut self.send, arg);
51        debug!("to do list updated");
52        trace!("out: {out:?}");
53        MsgraphCoroutineState::Complete(Ok(out))
54    }
55}