Support for comments
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use crate::{
|
||||
domain::PostEntry,
|
||||
routes::{AppError, Path, Query, not_found_html},
|
||||
routes::{
|
||||
AppError, Path, Query, fetch_comments_count, fetch_comments_page, get_comments_page_count,
|
||||
not_found_html,
|
||||
},
|
||||
startup::AppState,
|
||||
templates::{HtmlTemplate, PostListTemplate, PostTemplate, PostsTemplate},
|
||||
};
|
||||
@@ -89,7 +92,21 @@ pub async fn see_post(
|
||||
let post = post
|
||||
.to_html()
|
||||
.context("Could not render markdown with extension.")?;
|
||||
let template = HtmlTemplate(PostTemplate { post });
|
||||
let current_page = 1;
|
||||
let comments_count = fetch_comments_count(&connection_pool, post_id)
|
||||
.await
|
||||
.context("Could not fetch comment count")?;
|
||||
let max_page = get_comments_page_count(comments_count);
|
||||
let comments = fetch_comments_page(&connection_pool, post_id, 1)
|
||||
.await
|
||||
.context("Failed to fetch latest comments")?;
|
||||
let template = HtmlTemplate(PostTemplate {
|
||||
post,
|
||||
comments,
|
||||
current_page,
|
||||
max_page,
|
||||
comments_count,
|
||||
});
|
||||
Ok(template.into_response())
|
||||
} else {
|
||||
Ok(not_found_html())
|
||||
|
||||
Reference in New Issue
Block a user