use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Default)]
pub struct CreateSectionBody {
pub summary: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct UpdateSectionBody {
#[serde(skip_serializing_if = "Option::is_none")]
pub summary: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct CreateSectionResponse {
pub section_guid: String,
pub summary: String,
#[serde(default)]
pub description: Option<String>,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetSectionResponse {
pub section_guid: String,
pub summary: String,
#[serde(default)]
pub description: Option<String>,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct UpdateSectionResponse {
pub section_guid: String,
pub summary: String,
#[serde(default)]
pub description: Option<String>,
pub updated_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DeleteSectionResponse {
pub success: bool,
pub section_guid: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SectionItem {
pub section_guid: String,
pub summary: String,
#[serde(default)]
pub description: Option<String>,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ListSectionsResponse {
#[serde(default)]
pub has_more: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub page_token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub total: Option<i32>,
#[serde(default)]
pub items: Vec<SectionItem>,
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
assert_eq!(value["field"], "data");
}
}