From 5786d9ef1aa978e33c33d9566128410a59943740 Mon Sep 17 00:00:00 2001 From: adlee-was-taken Date: Sun, 19 Apr 2026 13:08:03 -0400 Subject: [PATCH] feat(core): flesh out DocumentCore Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/idfoto-core/src/item_types/document.rs | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) 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"); + } +}