diff options
| author | Tolmachev Igor <me@igorek.dev> | 2025-09-14 23:27:25 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2025-09-14 23:27:25 +0300 |
| commit | 955598dce9aeb5626654c72b0ef94850123fa8ac (patch) | |
| tree | 4fb161c2e67fdc161ebbca5ced271b6e7724dc30 /src/response.rs | |
| parent | 39bf8397949ea2738ac3dfc934fcc3f07a6b0b66 (diff) | |
| download | queue_server-955598dce9aeb5626654c72b0ef94850123fa8ac.tar.gz queue_server-955598dce9aeb5626654c72b0ef94850123fa8ac.zip | |
Add openapi specs and docs
Diffstat (limited to 'src/response.rs')
| -rw-r--r-- | src/response.rs | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/response.rs b/src/response.rs deleted file mode 100644 index a633570..0000000 --- a/src/response.rs +++ /dev/null | |||
| @@ -1,54 +0,0 @@ | |||
| 1 | use axum::{ | ||
| 2 | http::StatusCode, | ||
| 3 | response::{IntoResponse, Response}, | ||
| 4 | }; | ||
| 5 | use serde::Serialize; | ||
| 6 | use serde_json::json; | ||
| 7 | |||
| 8 | pub struct SuccessResponse<T>(pub T); | ||
| 9 | pub struct FailResponse(pub String, pub String); | ||
| 10 | pub struct ErrorResponse(pub String, pub String); | ||
| 11 | |||
| 12 | impl<T> IntoResponse for SuccessResponse<T> | ||
| 13 | where | ||
| 14 | T: Serialize, | ||
| 15 | { | ||
| 16 | fn into_response(self) -> Response { | ||
| 17 | ( | ||
| 18 | StatusCode::OK, | ||
| 19 | axum::Json(json!({ | ||
| 20 | "status": "success", | ||
| 21 | "data": self.0 | ||
| 22 | })), | ||
| 23 | ) | ||
| 24 | .into_response() | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | impl IntoResponse for FailResponse { | ||
| 29 | fn into_response(self) -> Response { | ||
| 30 | ( | ||
| 31 | StatusCode::BAD_REQUEST, | ||
| 32 | axum::Json(json!({ | ||
| 33 | "status": "fail", | ||
| 34 | "kind": self.0, | ||
| 35 | "message": self.1 | ||
| 36 | })), | ||
| 37 | ) | ||
| 38 | .into_response() | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | impl IntoResponse for ErrorResponse { | ||
| 43 | fn into_response(self) -> Response { | ||
| 44 | ( | ||
| 45 | StatusCode::INTERNAL_SERVER_ERROR, | ||
| 46 | axum::Json(json!({ | ||
| 47 | "status": "error", | ||
| 48 | "kind": self.0, | ||
| 49 | "message": self.1 | ||
| 50 | })), | ||
| 51 | ) | ||
| 52 | .into_response() | ||
| 53 | } | ||
| 54 | } | ||
