User comments
This commit is contained in:
@@ -77,7 +77,7 @@ async fn get_posts(
|
||||
sqlx::query_as!(
|
||||
PostEntry,
|
||||
r#"
|
||||
SELECT p.post_id, u.username AS author, p.title, p.content, p.published_at
|
||||
SELECT p.post_id, p.author_id, u.username AS author, p.title, p.content, p.published_at
|
||||
FROM posts p
|
||||
LEFT JOIN users u ON p.author_id = u.user_id
|
||||
ORDER BY p.published_at DESC
|
||||
@@ -99,7 +99,7 @@ pub async fn get_posts_page(
|
||||
sqlx::query_as!(
|
||||
PostEntry,
|
||||
r#"
|
||||
SELECT p.post_id, u.username AS author, p.title, p.content, p.published_at
|
||||
SELECT p.post_id, p.author_id, u.username AS author, p.title, p.content, p.published_at
|
||||
FROM posts p
|
||||
LEFT JOIN users u ON p.author_id = u.user_id
|
||||
ORDER BY p.published_at DESC
|
||||
@@ -197,7 +197,7 @@ pub async fn see_post(
|
||||
|
||||
if let Some(post) = get_post_data(&connection_pool, post_id)
|
||||
.await
|
||||
.context(format!("Failed to fetch post #{}", post_id))
|
||||
.context(format!("Failed to fetch post #{}.", post_id))
|
||||
.map_err(AppError::unexpected_page)?
|
||||
{
|
||||
let post_html = post
|
||||
@@ -206,16 +206,20 @@ pub async fn see_post(
|
||||
let current_page = 1;
|
||||
let comments_count = get_comments_count_for_post(&connection_pool, post_id)
|
||||
.await
|
||||
.context("Could not fetch comment count")?;
|
||||
.context("Could not fetch comment count.")?;
|
||||
let max_page = get_max_page(comments_count, COMMENTS_PER_PAGE);
|
||||
let comments = get_comments_page_for_post(&connection_pool, post_id, 1)
|
||||
.await
|
||||
.context("Failed to fetch latest comments")?;
|
||||
.context("Failed to fetch latest comments.")?;
|
||||
let idempotency_key = Uuid::new_v4().to_string();
|
||||
let session_user_id = session
|
||||
.get_user_id()
|
||||
.await
|
||||
.context("Could not check for session user id.")?;
|
||||
let session_username = session
|
||||
.get_username()
|
||||
.await
|
||||
.context("Could not check for session username")?;
|
||||
.context("Could not check for session username.")?;
|
||||
let template = HtmlTemplate(PostTemplate {
|
||||
post,
|
||||
post_html,
|
||||
@@ -224,6 +228,7 @@ pub async fn see_post(
|
||||
current_page,
|
||||
max_page,
|
||||
comments_count,
|
||||
session_user_id,
|
||||
session_username,
|
||||
});
|
||||
Ok(template.into_response())
|
||||
@@ -252,7 +257,7 @@ async fn get_post_data(
|
||||
sqlx::query_as!(
|
||||
PostEntry,
|
||||
r#"
|
||||
SELECT p.post_id, u.username AS author, p.title, p.content, p.published_at
|
||||
SELECT p.post_id, p.author_id, u.username AS author, p.title, p.content, p.published_at
|
||||
FROM posts p
|
||||
LEFT JOIN users u ON p.author_id = u.user_id
|
||||
WHERE p.post_id = $1
|
||||
|
||||
Reference in New Issue
Block a user