Skip to main content

io_msgraph/v1/rest/users/events/
update.rs

1//! Update a Microsoft Graph event (`PATCH /me/events/{id}`).
2//!
3//! <https://learn.microsoft.com/en-us/graph/api/event-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::events::MsgraphEvent,
16        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
17    },
18};
19
20/// Updates a Microsoft Graph event.
21pub struct MsgraphEventUpdate {
22    send: MsgraphSend<MsgraphEvent>,
23}
24
25impl MsgraphEventUpdate {
26    /// Patches the event `id` with the set and null fields of `event`.
27    pub fn new(
28        auth: &HttpAuthBearer,
29        user_id: &str,
30        id: &str,
31        event: &MsgraphEvent,
32    ) -> Result<Self, MsgraphSendError> {
33        debug!("prepare microsoft graph event update");
34        trace!("id: {id:?}");
35        trace!("event: {event:?}");
36
37        let user = user_path(user_id);
38        let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/events/{id}"))?;
39        let send = MsgraphSend::patch_json(auth, url, event)?;
40
41        Ok(Self { send })
42    }
43}
44
45impl MsgraphCoroutine for MsgraphEventUpdate {
46    type Yield = MsgraphYield;
47    type Return = Result<MsgraphSendOutput<MsgraphEvent>, 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!("event updated");
52        trace!("out: {out:?}");
53        MsgraphCoroutineState::Complete(Ok(out))
54    }
55}