Initial Bard library commit.
This was added to test the database into server context pipeline.
This commit is contained in:
27
bard/src/server.rs
Normal file
27
bard/src/server.rs
Normal 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()))
|
||||
}
|
||||
Reference in New Issue
Block a user