added recent posts endpoint, added image column to authors table
This commit is contained in:
@@ -11,7 +11,7 @@ impl AuthorsDatasource {
|
||||
let offset: i64 = (pagination.page_number - 1) * pagination.page_size;
|
||||
sqlx::query_as!(
|
||||
Author,
|
||||
"SELECT author_id, first_name, last_name, bio FROM authors ORDER BY created_at DESC LIMIT $1 OFFSET $2",
|
||||
"SELECT author_id, first_name, last_name, bio, image FROM authors ORDER BY created_at DESC LIMIT $1 OFFSET $2",
|
||||
pagination.page_size,
|
||||
offset,
|
||||
)
|
||||
@@ -22,7 +22,7 @@ impl AuthorsDatasource {
|
||||
pub async fn get_one(pool: &Pool<Postgres>, author_id: i32) -> Result<Author, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Author,
|
||||
"SELECT author_id, first_name, last_name, bio FROM authors WHERE author_id = $1",
|
||||
"SELECT author_id, first_name, last_name, bio, image FROM authors WHERE author_id = $1",
|
||||
author_id
|
||||
)
|
||||
.fetch_one(pool)
|
||||
@@ -35,7 +35,7 @@ impl AuthorsDatasource {
|
||||
) -> Result<Vec<Post>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Post,
|
||||
"SELECT p.post_id, a.first_name, a.last_name, p.title, p.body, p.created_at FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.author_id = $1 ORDER BY created_at DESC",
|
||||
"SELECT p.post_id, a.first_name, a.last_name, p.title, p.body, p.created_at, a.author_id FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.author_id = $1 ORDER BY created_at DESC",
|
||||
author_id
|
||||
)
|
||||
.fetch_all(pool)
|
||||
|
Reference in New Issue
Block a user