Support for comments
Some checks failed
Rust / Test (push) Successful in 5m31s
Rust / Rustfmt (push) Successful in 22s
Rust / Clippy (push) Failing after 27s
Rust / Code coverage (push) Successful in 4m28s

This commit is contained in:
Alphonse Paix
2025-10-02 00:26:18 +02:00
parent 2c7282475f
commit 9e5d185aaf
15 changed files with 402 additions and 2751 deletions

View File

@@ -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())