use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct NotificationsClient {
pub http_client: HttpClient,
}
impl NotificationsClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
pub async fn list_all_notifications(
&self,
request: &ListAllNotificationsQueryRequest,
options: Option<RequestOptions>,
) -> Result<GetNotificationsResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"notifications",
None,
QueryBuilder::new()
.int("page", request.page.clone())
.int("limit", request.limit.clone())
.string("search", request.search.clone())
.build(),
options,
)
.await
}
pub async fn create_a_notification(
&self,
request: &PostNotificationsRequest,
options: Option<RequestOptions>,
) -> Result<PostNotificationsResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"notifications",
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
pub async fn get_a_notification(
&self,
id: &String,
options: Option<RequestOptions>,
) -> Result<GetNotificationsIDResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("notifications/{}", id),
None,
None,
options,
)
.await
}
pub async fn delete_a_notification(
&self,
id: &String,
options: Option<RequestOptions>,
) -> Result<DeleteNotificationsIDResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("notifications/{}", id),
None,
None,
options,
)
.await
}
pub async fn update_a_notification(
&self,
id: &String,
request: &PatchNotificationsIDRequest,
options: Option<RequestOptions>,
) -> Result<PatchNotificationsIDResponse, ApiError> {
self.http_client
.execute_request(
Method::PATCH,
&format!("notifications/{}", id),
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
}