28 lines
890 B
Rust
28 lines
890 B
Rust
|
|
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()))
|
||
|
|
}
|