use serde::Serialize; #[derive(Debug, Serialize, utoipa::ToSchema)] pub struct ApiResponse { /// Business payload returned by the endpoint. pub data: T, } #[derive(Debug, Serialize, utoipa::ToSchema)] pub struct ApiEmptyResponse { /// Human-readable success message. pub message: String, } #[derive(Debug, Serialize, utoipa::ToSchema)] pub struct ApiErrorResponse { /// Stable, client-safe error message. pub error: String, } #[derive(Debug, Serialize, utoipa::ToSchema)] pub struct ApiListResponse { pub data: Vec, pub total: i64, pub page: i64, pub per_page: i64, } impl ApiResponse { pub fn new(data: T) -> Self { Self { data } } } impl ApiEmptyResponse { pub fn ok(message: impl Into) -> Self { Self { message: message.into(), } } } impl ApiListResponse { pub fn new(data: Vec, total: i64, page: i64, per_page: i64) -> Self { Self { data, total, page, per_page, } } pub fn empty() -> Self { Self { data: vec![], total: 0, page: 0, per_page: 0, } } } impl From<(Vec, i64, i64, i64)> for ApiListResponse { fn from(value: (Vec, i64, i64, i64)) -> Self { Self::new(value.0, value.1, value.2, value.3) } }