Initial Bard library commit.

This was added to test the database into server context pipeline.
This commit is contained in:
2025-09-02 14:00:19 -04:00
parent 3fc6bf0666
commit 877d7e15a3
4 changed files with 279 additions and 1 deletions

27
bard/src/server.rs Normal file
View File

@ -0,0 +1,27 @@
use dioxus::prelude::*;
use std::sync::Arc;
use crate::{Database, Lore, Tale};
#[server]
pub async fn get_blog_list() -> Result<Vec<Lore>, ServerFnError> {
let db = server_context()
.get::<Arc<Database>>()
.ok_or_else(|| ServerFnError::ServerError("Database context not available".to_string()))?;
let summaries = db.get_tales_summary(&[]).await
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
Ok(summaries)
}
#[server]
pub async fn get_blog_post(slug: String) -> Result<Tale, ServerFnError> {
let db = server_context()
.get::<Arc<Database>>()
.ok_or_else(|| ServerFnError::ServerError("Database context not available".to_string()))?;
let tale = db.get_tale_by_slug(&slug).await
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
tale.ok_or(ServerFnError::ServerError("Post not found".into()))
}