diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 4f8ec55..5ee3b2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,7 @@ use tracing_subscriber::FmtSubscriber; use crate::article::Article; use crate::blog::Blogpost; +use crate::poetry::Poem; use crate::posts::Post; type Result<T> = std::result::Result<T, BlossomError>; @@ -123,6 +124,20 @@ async fn plants() -> Result<()> { Err(BlossomError::Unimplemented) } +#[handler] +async fn get_poem(Path(poem): Path<String>) -> Result<templates::Poem> { + let poem = Poem::get_article(&poem).await?; + Ok(templates::Poem { poem, jiggle: 4 }) +} + +#[handler] +async fn get_poetry() -> Result<templates::Poetry> { + let mut poems = Poem::get_articles().await?; + poems.sort_by_key(|poem| poem.created_at); + poems.reverse(); + Ok(templates::Poetry { poems, jiggle: 16 }) +} + async fn custom_error(err: poem::Error) -> impl IntoResponse { templates::Error { status: err.status(), @@ -143,6 +158,8 @@ async fn main() -> std::result::Result<(), std::io::Error> { .at("/", get(home)) .at("/blog", get(get_blog)) .at("/blog/:blogpost", get(blogpost)) + .at("/poetry", get(get_poetry)) + .at("/poetry/:poem", get(get_poem)) .at("/feed", get(feed)) .at("/contact", get(contact)) .at("/plants", get(plants)) |