Record login for users
Some checks failed
Rust / Test (push) Failing after 4m54s
Rust / Rustfmt (push) Successful in 21s
Rust / Clippy (push) Failing after 1m36s
Rust / Code coverage (push) Successful in 5m4s

This commit is contained in:
Alphonse Paix
2025-10-09 21:05:48 +02:00
parent 45f529902d
commit e02139ff44
14 changed files with 155 additions and 69 deletions

View File

@@ -17,6 +17,7 @@ use axum::{
extract::State,
response::{Html, IntoResponse, Redirect, Response},
};
use chrono::Utc;
use sqlx::PgPool;
use uuid::Uuid;
use validator::Validate;
@@ -77,7 +78,8 @@ async fn get_posts(
sqlx::query_as!(
PostEntry,
r#"
SELECT p.post_id, p.author_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, p.last_modified
FROM posts p
LEFT JOIN users u ON p.author_id = u.user_id
ORDER BY p.published_at DESC
@@ -99,7 +101,8 @@ pub async fn get_posts_page(
sqlx::query_as!(
PostEntry,
r#"
SELECT p.post_id, p.author_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, p.last_modified
FROM posts p
LEFT JOIN users u ON p.author_id = u.user_id
ORDER BY p.published_at DESC
@@ -151,10 +154,11 @@ pub async fn update_post(
sqlx::query!(
"
UPDATE posts
SET title = $1, content = $2 WHERE post_id = $3
SET title = $1, content = $2, last_modified = $3 WHERE post_id = $4
",
form.title,
form.content,
Utc::now(),
post_id
)
.execute(&connection_pool)
@@ -257,7 +261,8 @@ async fn get_post_data(
sqlx::query_as!(
PostEntry,
r#"
SELECT p.post_id, p.author_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, last_modified
FROM posts p
LEFT JOIN users u ON p.author_id = u.user_id
WHERE p.post_id = $1