diff --git a/crates/idfoto-core/src/item_types/document.rs b/crates/idfoto-core/src/item_types/document.rs index 5a16eb4..d6e8714 100644 --- a/crates/idfoto-core/src/item_types/document.rs +++ b/crates/idfoto-core/src/item_types/document.rs @@ -1,3 +1,40 @@ +//! Document: filename + mime + pointer to the primary attachment blob. + use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, Serialize, Deserialize, Default)] -pub struct DocumentCore {} + +use crate::ids::AttachmentId; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DocumentCore { + pub filename: String, + pub mime_type: String, + pub primary_attachment: AttachmentId, +} + +impl Default for DocumentCore { + fn default() -> Self { + Self { + filename: String::new(), + mime_type: "application/octet-stream".into(), + primary_attachment: AttachmentId(String::new()), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn document_round_trip() { + let doc = DocumentCore { + filename: "passport.pdf".into(), + mime_type: "application/pdf".into(), + primary_attachment: AttachmentId("0123456789abcdef".into()), + }; + let json = serde_json::to_string(&doc).unwrap(); + let parsed: DocumentCore = serde_json::from_str(&json).unwrap(); + assert_eq!(parsed.filename, "passport.pdf"); + assert_eq!(parsed.primary_attachment.as_str(), "0123456789abcdef"); + } +}