use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use serde::Serialize; use serde_json::json; pub struct SuccessResponse(pub T); pub struct FailResponse(pub String, pub String); pub struct ErrorResponse(pub String, pub String); impl IntoResponse for SuccessResponse where T: Serialize, { fn into_response(self) -> Response { ( StatusCode::OK, axum::Json(json!({ "status": "success", "data": self.0 })), ) .into_response() } } impl IntoResponse for FailResponse { fn into_response(self) -> Response { ( StatusCode::BAD_REQUEST, axum::Json(json!({ "status": "fail", "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", "kind": self.0, "message": self.1 })), ) .into_response() } }