From b9d75e22db72aabf47815e381aa6432c1bff3877 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Mon, 1 Sep 2025 13:32:05 +0300 Subject: Add account endpoints --- src/response.rs | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'src/response.rs') diff --git a/src/response.rs b/src/response.rs index 8d505a5..25c3008 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,32 +1,52 @@ +use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use serde::Serialize; use serde_json::json; -pub enum ApiResponse { - Success(T), - Fail(T), - Error(String), -} +pub struct SuccessResponse(pub T); +pub struct FailResponse(pub String, pub String); +pub struct ErrorResponse(pub String, pub String); -impl IntoResponse for ApiResponse +impl IntoResponse for SuccessResponse where T: Serialize, { fn into_response(self) -> Response { - axum::Json(match self { - ApiResponse::Success(data) => json!({ + ( + StatusCode::OK, + axum::Json(json!({ "status": "success", - "data": data - }), - ApiResponse::Fail(data) => json!({ + "data": self.0 + })), + ) + .into_response() + } +} + +impl IntoResponse for FailResponse { + fn into_response(self) -> Response { + ( + StatusCode::BAD_REQUEST, + axum::Json(json!({ "status": "fail", - "data": data - }), - ApiResponse::Error(message) => json!({ + "kind": self.0, + "message": self.1 + })), + ) + .into_response() + } +} + +impl IntoResponse for ErrorResponse { + fn into_response(self) -> Response { + ( + StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(json!({ "status": "error", - "message": message - }), - }) - .into_response() + "kind": self.0, + "message": self.1 + })), + ) + .into_response() } } -- cgit v1.2.3