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
16#[derive(Debug, Clone, Default, PartialEq)]
18pub struct ListNotificationsParams {
19 pub read: Option<bool>,
21}
22
23pub struct NotificationsService<'a> {
25 scope: Scope<'a>,
26}
27
28impl<'a> NotificationsService<'a> {
29 pub(crate) fn new(scope: Scope<'a>) -> Self {
30 Self { scope }
31 }
32
33 pub fn scope(&self) -> &Scope<'a> {
35 &self.scope
36 }
37
38 pub async fn bulk_read(&self, body: &BulkReadNotificationsRequestContent) -> Result<(), Error> {
42 let mut operation = self
43 .scope
44 .operation(&routes::BULK_READ_NOTIFICATIONS, &[])?;
45 operation.json(body)?;
46 self.scope.client().send_unit(operation).await
47 }
48
49 pub async fn get_settings(&self) -> Result<NotificationSettings, Error> {
53 let operation = self
54 .scope
55 .operation(&routes::GET_NOTIFICATION_SETTINGS, &[])?;
56 self.scope.client().send(operation).await
57 }
58
59 pub async fn get_tray(
63 &self,
64 params: &GetNotificationTrayParams,
65 ) -> Result<Vec<Notification>, Error> {
66 let mut operation = self.scope.operation(&routes::GET_NOTIFICATION_TRAY, &[])?;
67 operation.query_optional("include_read", params.include_read.as_ref());
68 self.scope.client().send(operation).await
69 }
70
71 pub async fn list(
77 &self,
78 params: &ListNotificationsParams,
79 ) -> Result<Page<Vec<Notification>>, Error> {
80 let mut operation = self.scope.operation(&routes::LIST_NOTIFICATIONS, &[])?;
81 operation.query_optional("read", params.read.as_ref());
82 self.scope.client().send_page(operation).await
83 }
84
85 pub async fn read(&self, notification_id: &str) -> Result<(), Error> {
89 let mut operation = self
90 .scope
91 .operation(&routes::READ_NOTIFICATION, &[¬ification_id])?;
92 operation.resource_id(notification_id);
93 self.scope.client().send_unit(operation).await
94 }
95
96 pub async fn unread(&self, notification_id: &str) -> Result<(), Error> {
100 let mut operation = self
101 .scope
102 .operation(&routes::UNREAD_NOTIFICATION, &[¬ification_id])?;
103 operation.resource_id(notification_id);
104 self.scope.client().send_unit(operation).await
105 }
106
107 pub async fn update_settings(
111 &self,
112 body: &UpdateNotificationSettingsRequestContent,
113 ) -> Result<(), Error> {
114 let mut operation = self
115 .scope
116 .operation(&routes::UPDATE_NOTIFICATION_SETTINGS, &[])?;
117 operation.json(body)?;
118 self.scope.client().send_unit(operation).await
119 }
120}