65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
|
use serde::Serialize;
|
||
|
use time::OffsetDateTime;
|
||
|
|
||
|
use super::{content::Content, link::Link};
|
||
|
|
||
|
#[derive(Debug, Serialize)]
|
||
|
#[serde(rename = "entry")]
|
||
|
pub struct Entry {
|
||
|
pub title: String,
|
||
|
pub id: String,
|
||
|
#[serde(with = "time::serde::rfc3339")]
|
||
|
pub updated: OffsetDateTime,
|
||
|
pub content: Content,
|
||
|
#[serde(rename = "link")]
|
||
|
pub links: Vec<Link>,
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use quick_xml::se::to_string;
|
||
|
use time::macros::datetime;
|
||
|
|
||
|
use crate::opds::{content::Content, media_type::MediaType, relation::Relation};
|
||
|
|
||
|
use super::*;
|
||
|
|
||
|
fn init() -> Entry {
|
||
|
Entry {
|
||
|
title: "Authors".to_string(),
|
||
|
id: "rust:authors".to_string(),
|
||
|
updated: datetime!(2024-05-06 19:14:54 UTC),
|
||
|
content: Content {
|
||
|
media_type: MediaType::Text,
|
||
|
content: "All authors".to_string(),
|
||
|
},
|
||
|
links: vec![
|
||
|
Link {
|
||
|
href: "/opds".to_string(),
|
||
|
media_type: MediaType::Text,
|
||
|
rel: Relation::Start,
|
||
|
title: None,
|
||
|
count: None,
|
||
|
},
|
||
|
Link {
|
||
|
href: "/opds".to_string(),
|
||
|
media_type: MediaType::Text,
|
||
|
rel: Relation::Start,
|
||
|
title: None,
|
||
|
count: None,
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn serialize() {
|
||
|
let entry = init();
|
||
|
let xml = to_string(&entry).unwrap();
|
||
|
assert_eq!(
|
||
|
xml,
|
||
|
r#"<entry><title>Authors</title><id>rust:authors</id><updated>2024-05-06T19:14:54Z</updated><content type="text">All authors</content><link href="/opds" type="text" rel="start"/><link href="/opds" type="text" rel="start"/></entry>"#
|
||
|
);
|
||
|
}
|
||
|
}
|