fizzy_sdk/generated/services/
notifications.rs1use crate::client::Scope;
4use crate::error::Error;
5use crate::generated::routes;
6use crate::generated::types::*;
7use crate::pagination::Page;
8
9#[derive(Debug, Clone, Default, PartialEq)]
11pub struct GetNotificationTrayParams {
12 pub include_read: Option<bool>,
14}
15
16pub struct NotificationsService<'a> {
18 scope: Scope<'a>,
19}
20
21impl<'a> NotificationsService<'a> {
22 pub(crate) fn new(scope: Scope<'a>) -> Self {
23 Self { scope }
24 }
25
26 pub fn scope(&self) -> &Scope<'a> {
28 &self.scope
29 }
30
31 pub async fn bulk_read(&self, body: &BulkReadNotificationsRequestContent) -> Result<(), Error> {
35 let mut operation = self
36 .scope
37 .operation(&routes::BULK_READ_NOTIFICATIONS, &[])?;
38 operation.json(body)?;
39 self.scope.client().send_unit(operation).await
40 }
41
42 pub async fn get_settings(&self) -> Result<NotificationSettings, Error> {
46 let operation = self
47 .scope
48 .operation(&routes::GET_NOTIFICATION_SETTINGS, &[])?;
49 self.scope.client().send(operation).await
50 }
51
52 pub async fn get_tray(
56 &self,
57 params: &GetNotificationTrayParams,
58 ) -> Result<Vec<Notification>, Error> {
59 let mut operation = self.scope.operation(&routes::GET_NOTIFICATION_TRAY, &[])?;
60 operation.query_optional("include_read", params.include_read.as_ref());
61 self.scope.client().send(operation).await
62 }
63
64 pub async fn list(&self) -> Result<Page<Vec<Notification>>, Error> {
70 let operation = self.scope.operation(&routes::LIST_NOTIFICATIONS, &[])?;
71 self.scope.client().send_page(operation).await
72 }
73
74 pub async fn read(&self, notification_id: &str) -> Result<(), Error> {
78 let mut operation = self
79 .scope
80 .operation(&routes::READ_NOTIFICATION, &[¬ification_id])?;
81 operation.resource_id(notification_id);
82 self.scope.client().send_unit(operation).await
83 }
84
85 pub async fn unread(&self, notification_id: &str) -> Result<(), Error> {
89 let mut operation = self
90 .scope
91 .operation(&routes::UNREAD_NOTIFICATION, &[¬ification_id])?;
92 operation.resource_id(notification_id);
93 self.scope.client().send_unit(operation).await
94 }
95
96 pub async fn update_settings(
100 &self,
101 body: &UpdateNotificationSettingsRequestContent,
102 ) -> Result<(), Error> {
103 let mut operation = self
104 .scope
105 .operation(&routes::UPDATE_NOTIFICATION_SETTINGS, &[])?;
106 operation.json(body)?;
107 self.scope.client().send_unit(operation).await
108 }
109}