From a57b2db1ffdacc1263e44d0ec69cebbbcdeec759 Mon Sep 17 00:00:00 2001 From: Myrddin Dundragon Date: Fri, 29 Aug 2025 22:50:19 -0400 Subject: [PATCH] [#5] Tavern components added to database. --- tavern/Cargo.toml | 2 +- tavern/src/database.rs | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tavern/Cargo.toml b/tavern/Cargo.toml index 48ac791..de383a6 100644 --- a/tavern/Cargo.toml +++ b/tavern/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tavern" -version = "0.2.2" +version = "0.2.3" edition = "2024" description = "A blogging system that will allow you to write your blog in Markdown and then display it in HTML using Dioxus." repository = "/CyberMages/tavern" diff --git a/tavern/src/database.rs b/tavern/src/database.rs index 4af65f2..076a898 100644 --- a/tavern/src/database.rs +++ b/tavern/src/database.rs @@ -12,6 +12,8 @@ use crate::tale::Tale; #[cfg(feature = "publisher")] use crate::converter::Converter; +#[cfg(feature = "publisher")] +use crate::tavern::Tavern; #[cfg(not(feature = "publisher"))] use crate::tale::Lore; @@ -135,7 +137,7 @@ impl Database /// Inserts a single tale into the database. #[cfg(feature = "publisher")] pub async fn insert_tale(&self, tale: &Tale) - -> Result<(), Box> + -> Result<()> { // Convert the tales content from Markdown to HTML. let markdown_content = std::fs::read_to_string(&tale.story)?; @@ -218,7 +220,7 @@ impl Database /// Inserts the site-wide settings like title and description. #[cfg(feature = "publisher")] - pub async fn insert_tavern(&self, title: &str, description: &str) + pub async fn insert_tavern_settings(&self, title: &str, description: &str) -> Result<()> { // Start a transaction. @@ -242,6 +244,25 @@ impl Database Ok(()) } + /// Inserts a Tavern into the database. + #[cfg(feature = "publisher")] + pub async fn insert_tavern(&self, tavern: &Tavern) -> Result<()> + { + self.insert_tavern_settings(&tavern.title, &tavern.description).await?; + + for tale in &tavern.tales + { + self.insert_tale(tale).await?; + } + + for author in &tavern.authors + { + self.insert_adventurer(author).await?; + } + + Ok(()) + } + #[cfg(not(feature = "publisher"))] pub async fn get_tales_summary(&self, categories: &[String]) -> Result>