Files
zero2prod/src/domain/post.rs
Alphonse Paix ef9f860da2
All checks were successful
Rust / Test (push) Successful in 6m17s
Rust / Rustfmt (push) Successful in 21s
Rust / Clippy (push) Successful in 1m37s
Rust / Code coverage (push) Successful in 5m5s
User comments
2025-10-08 14:23:43 +02:00

25 lines
597 B
Rust

use chrono::{DateTime, Utc};
use uuid::Uuid;
pub struct PostEntry {
pub post_id: Uuid,
pub author_id: Uuid,
pub author: String,
pub title: String,
pub content: String,
pub published_at: DateTime<Utc>,
}
impl PostEntry {
pub fn formatted_date(&self) -> String {
self.published_at.format("%B %d, %Y").to_string()
}
pub fn to_html(&self) -> anyhow::Result<String> {
match markdown::to_html_with_options(&self.content, &markdown::Options::gfm()) {
Ok(content) => Ok(content),
Err(e) => anyhow::bail!(e),
}
}
}