openzeppelin_relayer/api/routes/docs/
notification_docs.rs

1use crate::models::{
2    ApiResponse, NotificationCreateRequest, NotificationResponse, NotificationUpdateRequest,
3};
4
5/// Notification routes implementation
6///
7/// Note: OpenAPI documentation for these endpoints can be found in the `openapi.rs` file
8///
9/// Lists all notifications with pagination support.
10#[utoipa::path(
11    get,
12    path = "/api/v1/notifications",
13    tag = "Notifications",
14    operation_id = "listNotifications",
15    security(
16        ("bearer_auth" = [])
17    ),
18    params(
19        ("page" = Option<usize>, Query, description = "Page number for pagination (starts at 1)"),
20        ("per_page" = Option<usize>, Query, description = "Number of items per page (default: 10)")
21    ),
22    responses(
23        (
24            status = 200,
25            description = "Notification list retrieved successfully",
26            body = ApiResponse<Vec<NotificationResponse>>
27        ),
28        (
29            status = 400,
30            description = "Bad Request",
31            body = ApiResponse<String>,
32            example = json!({
33                "success": false,
34                "message": "Bad Request",
35                "data": null
36            })
37        ),
38        (
39            status = 401,
40            description = "Unauthorized",
41            body = ApiResponse<String>,
42            example = json!({
43                "success": false,
44                "message": "Unauthorized",
45                "data": null
46            })
47        ),
48        (
49            status = 500,
50            description = "Internal Server Error",
51            body = ApiResponse<String>,
52            example = json!({
53                "success": false,
54                "message": "Internal Server Error",
55                "data": null
56            })
57        )
58    )
59)]
60#[allow(dead_code)]
61fn doc_list_notifications() {}
62
63/// Retrieves details of a specific notification by ID.
64#[utoipa::path(
65    get,
66    path = "/api/v1/notifications/{notification_id}",
67    tag = "Notifications",
68    operation_id = "getNotification",
69    security(
70        ("bearer_auth" = [])
71    ),
72    params(
73        ("notification_id" = String, Path, description = "Notification ID")
74    ),
75    responses(
76        (
77            status = 200,
78            description = "Notification retrieved successfully",
79            body = ApiResponse<NotificationResponse>
80        ),
81        (
82            status = 400,
83            description = "Bad Request",
84            body = ApiResponse<String>,
85            example = json!({
86                "success": false,
87                "message": "Bad Request",
88                "data": null
89            })
90        ),
91        (
92            status = 401,
93            description = "Unauthorized",
94            body = ApiResponse<String>,
95            example = json!({
96                "success": false,
97                "message": "Unauthorized",
98                "data": null
99            })
100        ),
101        (
102            status = 404,
103            description = "Notification not found",
104            body = ApiResponse<String>,
105            example = json!({
106                "success": false,
107                "message": "Notification not found",
108                "data": null
109            })
110        ),
111        (
112            status = 500,
113            description = "Internal Server Error",
114            body = ApiResponse<String>,
115            example = json!({
116                "success": false,
117                "message": "Internal Server Error",
118                "data": null
119            })
120        )
121    )
122)]
123#[allow(dead_code)]
124fn doc_get_notification() {}
125
126/// Creates a new notification.
127#[utoipa::path(
128    post,
129    path = "/api/v1/notifications",
130    tag = "Notifications",
131    operation_id = "createNotification",
132    security(
133        ("bearer_auth" = [])
134    ),
135    request_body = NotificationCreateRequest,
136    responses(
137        (
138            status = 201,
139            description = "Notification created successfully",
140            body = ApiResponse<NotificationResponse>
141        ),
142        (
143            status = 400,
144            description = "Bad Request",
145            body = ApiResponse<String>,
146            example = json!({
147                "success": false,
148                "message": "Bad Request",
149                "data": null
150            })
151        ),
152        (
153            status = 401,
154            description = "Unauthorized",
155            body = ApiResponse<String>,
156            example = json!({
157                "success": false,
158                "message": "Unauthorized",
159                "data": null
160            })
161        ),
162        (
163            status = 409,
164            description = "Notification with this ID already exists",
165            body = ApiResponse<String>,
166            example = json!({
167                "success": false,
168                "message": "Notification with this ID already exists",
169                "data": null
170            })
171        ),
172        (
173            status = 500,
174            description = "Internal Server Error",
175            body = ApiResponse<String>,
176            example = json!({
177                "success": false,
178                "message": "Internal Server Error",
179                "data": null
180            })
181        )
182    )
183)]
184#[allow(dead_code)]
185fn doc_create_notification() {}
186
187/// Updates an existing notification.
188#[utoipa::path(
189    patch,
190    path = "/api/v1/notifications/{notification_id}",
191    tag = "Notifications",
192    operation_id = "updateNotification",
193    security(
194        ("bearer_auth" = [])
195    ),
196    params(
197        ("notification_id" = String, Path, description = "Notification ID")
198    ),
199    request_body = NotificationUpdateRequest,
200    responses(
201        (
202            status = 200,
203            description = "Notification updated successfully",
204            body = ApiResponse<NotificationResponse>
205        ),
206        (
207            status = 400,
208            description = "Bad Request",
209            body = ApiResponse<String>,
210            example = json!({
211                "success": false,
212                "message": "Bad Request",
213                "data": null
214            })
215        ),
216        (
217            status = 401,
218            description = "Unauthorized",
219            body = ApiResponse<String>,
220            example = json!({
221                "success": false,
222                "message": "Unauthorized",
223                "data": null
224            })
225        ),
226        (
227            status = 404,
228            description = "Notification not found",
229            body = ApiResponse<String>,
230            example = json!({
231                "success": false,
232                "message": "Notification not found",
233                "data": null
234            })
235        ),
236        (
237            status = 500,
238            description = "Internal Server Error",
239            body = ApiResponse<String>,
240            example = json!({
241                "success": false,
242                "message": "Internal Server Error",
243                "data": null
244            })
245        )
246    )
247)]
248#[allow(dead_code)]
249fn doc_update_notification() {}
250
251/// Deletes a notification by ID.
252#[utoipa::path(
253    delete,
254    path = "/api/v1/notifications/{notification_id}",
255    tag = "Notifications",
256    operation_id = "deleteNotification",
257    security(
258        ("bearer_auth" = [])
259    ),
260    params(
261        ("notification_id" = String, Path, description = "Notification ID")
262    ),
263    responses(
264        (
265            status = 200,
266            description = "Notification deleted successfully",
267            body = ApiResponse<String>,
268            example = json!({
269                "success": true,
270                "message": "Notification deleted successfully",
271                "data": "Notification deleted successfully"
272            })
273        ),
274        (
275            status = 400,
276            description = "Bad Request",
277            body = ApiResponse<String>,
278            example = json!({
279                "success": false,
280                "message": "Bad Request",
281                "data": null
282            })
283        ),
284        (
285            status = 401,
286            description = "Unauthorized",
287            body = ApiResponse<String>,
288            example = json!({
289                "success": false,
290                "message": "Unauthorized",
291                "data": null
292            })
293        ),
294        (
295            status = 404,
296            description = "Notification not found",
297            body = ApiResponse<String>,
298            example = json!({
299                "success": false,
300                "message": "Notification not found",
301                "data": null
302            })
303        ),
304        (
305            status = 500,
306            description = "Internal Server Error",
307            body = ApiResponse<String>,
308            example = json!({
309                "success": false,
310                "message": "Internal Server Error",
311                "data": null
312            })
313        )
314    )
315)]
316#[allow(dead_code)]
317fn doc_delete_notification() {}