use std::collections::BTreeSet;
use serde::Serialize;
use crate::models::annotation::{Annotation, AnnotationMetadata, AnnotationStyle};
use crate::strings;
#[derive(Debug, Serialize)]
pub struct AnnotationContext<'a> {
#[allow(missing_docs)]
pub body: &'a str,
#[allow(missing_docs)]
pub style: &'a AnnotationStyle,
#[allow(missing_docs)]
pub notes: &'a str,
#[allow(missing_docs)]
pub tags: &'a BTreeSet<String>,
#[allow(missing_docs)]
pub metadata: &'a AnnotationMetadata,
pub slugs: AnnotationSlugs,
}
impl<'a> From<&'a Annotation> for AnnotationContext<'a> {
fn from(annotation: &'a Annotation) -> Self {
Self {
body: &annotation.body,
style: &annotation.style,
notes: &annotation.notes,
tags: &annotation.tags,
metadata: &annotation.metadata,
slugs: AnnotationSlugs {
metadata: AnnotationMetadataSlugs {
created: strings::to_slug_date(&annotation.metadata.created),
modified: strings::to_slug_date(&annotation.metadata.modified),
},
},
}
}
}
#[derive(Debug, Serialize)]
pub struct AnnotationSlugs {
#[allow(missing_docs)]
metadata: AnnotationMetadataSlugs,
}
#[derive(Debug, Serialize)]
pub struct AnnotationMetadataSlugs {
#[allow(missing_docs)]
created: String,
#[allow(missing_docs)]
modified: String,
}