artcoded_api/apis/
notification_controller_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum Delete1Error {
20 UnknownValue(serde_json::Value),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum GetLatestNotificationError {
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum UpdateError {
34 UnknownValue(serde_json::Value),
35}
36
37pub async fn delete1(
38 configuration: &configuration::Configuration,
39 id: &str,
40) -> Result<(), Error<Delete1Error>> {
41 let p_query_id = id;
43
44 let uri_str = format!("{}/api/notification", configuration.base_path);
45 let mut req_builder = configuration
46 .client
47 .request(reqwest::Method::DELETE, &uri_str);
48
49 req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
50 if let Some(ref user_agent) = configuration.user_agent {
51 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52 }
53 if let Some(ref token) = configuration.bearer_access_token {
54 req_builder = req_builder.bearer_auth(token.to_owned());
55 };
56
57 let req = req_builder.build()?;
58 let resp = configuration.client.execute(req).await?;
59
60 let status = resp.status();
61
62 if !status.is_client_error() && !status.is_server_error() {
63 Ok(())
64 } else {
65 let content = resp.text().await?;
66 let entity: Option<Delete1Error> = serde_json::from_str(&content).ok();
67 Err(Error::ResponseError(ResponseContent {
68 status,
69 content,
70 entity,
71 }))
72 }
73}
74
75pub async fn get_latest_notification(
76 configuration: &configuration::Configuration,
77) -> Result<Vec<models::Notification>, Error<GetLatestNotificationError>> {
78 let uri_str = format!("{}/api/notification", configuration.base_path);
79 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
80
81 if let Some(ref user_agent) = configuration.user_agent {
82 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83 }
84 if let Some(ref token) = configuration.bearer_access_token {
85 req_builder = req_builder.bearer_auth(token.to_owned());
86 };
87
88 let req = req_builder.build()?;
89 let resp = configuration.client.execute(req).await?;
90
91 let status = resp.status();
92 let content_type = resp
93 .headers()
94 .get("content-type")
95 .and_then(|v| v.to_str().ok())
96 .unwrap_or("application/octet-stream");
97 let content_type = super::ContentType::from(content_type);
98
99 if !status.is_client_error() && !status.is_server_error() {
100 let content = resp.text().await?;
101 match content_type {
102 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
103 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Notification>`"))),
104 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Notification>`")))),
105 }
106 } else {
107 let content = resp.text().await?;
108 let entity: Option<GetLatestNotificationError> = serde_json::from_str(&content).ok();
109 Err(Error::ResponseError(ResponseContent {
110 status,
111 content,
112 entity,
113 }))
114 }
115}
116
117pub async fn update(
118 configuration: &configuration::Configuration,
119 id: &str,
120 seen: bool,
121) -> Result<(), Error<UpdateError>> {
122 let p_query_id = id;
124 let p_query_seen = seen;
125
126 let uri_str = format!("{}/api/notification", configuration.base_path);
127 let mut req_builder = configuration
128 .client
129 .request(reqwest::Method::POST, &uri_str);
130
131 req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
132 req_builder = req_builder.query(&[("seen", &p_query_seen.to_string())]);
133 if let Some(ref user_agent) = configuration.user_agent {
134 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135 }
136 if let Some(ref token) = configuration.bearer_access_token {
137 req_builder = req_builder.bearer_auth(token.to_owned());
138 };
139
140 let req = req_builder.build()?;
141 let resp = configuration.client.execute(req).await?;
142
143 let status = resp.status();
144
145 if !status.is_client_error() && !status.is_server_error() {
146 Ok(())
147 } else {
148 let content = resp.text().await?;
149 let entity: Option<UpdateError> = serde_json::from_str(&content).ok();
150 Err(Error::ResponseError(ResponseContent {
151 status,
152 content,
153 entity,
154 }))
155 }
156}