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::{
17            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
18            user_path,
19        },
20    },
21};
22
23/// Updates a Microsoft Graph event.
24pub struct MsgraphEventUpdate {
25    send: MsgraphSend<MsgraphEvent>,
26}
27
28impl MsgraphEventUpdate {
29    /// Patches the event `id` with the set and null fields of `event`.
30    pub fn new(
31        auth: &HttpAuthBearer,
32        user_id: &str,
33        id: &str,
34        event: &MsgraphEvent,
35    ) -> Result<Self, MsgraphSendError> {
36        debug!("prepare microsoft graph event update");
37        trace!("id: {id:?}");
38        trace!("event: {event:?}");
39
40        let user = user_path(user_id)?;
41        let url =
42            Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/events/{}", path_segment(id)?))?;
43        let send = MsgraphSend::patch_json(auth, url, event)?;
44
45        Ok(Self { send })
46    }
47}
48
49impl MsgraphCoroutine for MsgraphEventUpdate {
50    type Yield = MsgraphYield;
51    type Return = Result<MsgraphSendOutput<MsgraphEvent>, MsgraphSendError>;
52
53    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
54        let out = msgraph_try!(&mut self.send, arg);
55        debug!("event updated");
56        trace!("out: {out:?}");
57        MsgraphCoroutineState::Complete(Ok(out))
58    }
59}