added pagination to a given authors page

This commit is contained in:
wymiller committed 2025-07-07 21:05:27 -04:00
1 parent a64b8fdceb
commit 6694f47d70
16 files changed
+350 -93

No files matched your search

+6 -3
View File
@@ -1,4 +1,7 @@
use crate::routes::comments::{Comment, CommentInputPayload, Pagination};
use crate::{
routes::comments::{Comment, CommentInputPayload},
utils::pagination::Pagination,
};
use sqlx::{Pool, Postgres};
pub struct CommentsDatasource;
@@ -25,8 +28,8 @@ impl CommentsDatasource {
pool: &Pool<Postgres>,
pagination: Pagination,
) -> Result<Vec<Comment>, sqlx::Error> {
let offset: i64 = (pagination.page_number - 1) * pagination.page_size;
sqlx::query_as!(Comment, "SELECT comment_id, name, body, created_at FROM comments ORDER BY created_at DESC LIMIT $1 OFFSET $2", pagination.page_size, offset)
let offset: i64 = (pagination.page - 1) * pagination.limit;
sqlx::query_as!(Comment, "SELECT comment_id, name, body, created_at FROM comments ORDER BY created_at DESC LIMIT $1 OFFSET $2", pagination.page, offset)
.fetch_all(pool)
.await
}