io_msgraph/v1/rest/users/messages/attachments/
list.rs1use alloc::{format, string::String, vec::Vec};
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use serde::{Deserialize, Serialize};
11use url::Url;
12
13use crate::{
14 coroutine::*,
15 msgraph_try,
16 v1::{
17 rest::users::messages::attachments::MsgraphAttachment,
18 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
19 },
20};
21
22#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
24pub struct MsgraphAttachmentsListResponse {
25 #[serde(default)]
27 pub value: Vec<MsgraphAttachment>,
28 #[serde(default, rename = "@odata.nextLink")]
30 pub next_link: Option<String>,
31}
32
33pub struct MsgraphAttachmentsList {
35 send: MsgraphSend<MsgraphAttachmentsListResponse>,
36}
37
38impl MsgraphAttachmentsList {
39 pub fn new(
41 auth: &HttpAuthBearer,
42 user_id: &str,
43 message_id: &str,
44 ) -> Result<Self, MsgraphSendError> {
45 debug!("prepare microsoft graph attachments listing");
46 trace!("message_id: {message_id:?}");
47
48 let user = user_path(user_id);
49 let url = Url::parse(MSGRAPH_API_BASE)?
50 .join(&format!("{user}/messages/{message_id}/attachments"))?;
51 let send = MsgraphSend::get(auth, url);
52
53 Ok(Self { send })
54 }
55}
56
57impl MsgraphCoroutine for MsgraphAttachmentsList {
58 type Yield = MsgraphYield;
59 type Return = Result<MsgraphSendOutput<MsgraphAttachmentsListResponse>, 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!("attachments listed");
64 trace!("out: {out:?}");
65 MsgraphCoroutineState::Complete(Ok(out))
66 }
67}