use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SortDirection {
Asc,
Desc,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperationResponse {
pub success: bool,
#[serde(default)]
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListResponse<T> {
pub items: Vec<T>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sort_direction_serde_roundtrip() {
let json = serde_json::to_string(&SortDirection::Asc).unwrap();
assert_eq!(json, r#""asc""#);
let parsed: SortDirection = serde_json::from_str(&json).unwrap();
assert_eq!(parsed, SortDirection::Asc);
}
#[test]
fn operation_response_deserialize() {
let json = r#"{"success": true, "message": "created"}"#;
let resp: OperationResponse = serde_json::from_str(json).unwrap();
assert!(resp.success);
assert_eq!(resp.message.as_deref(), Some("created"));
}
#[test]
fn operation_response_without_message() {
let json = r#"{"success": true}"#;
let resp: OperationResponse = serde_json::from_str(json).unwrap();
assert!(resp.success);
assert!(resp.message.is_none());
}
}