Manage posts on dashboard and templates fixes
This commit is contained in:
@@ -42,10 +42,10 @@ pub async fn admin_dashboard(
|
||||
.await
|
||||
.context("Could not fetch subscribers from database.")
|
||||
.map_err(AppError::unexpected_message)?;
|
||||
let count = get_total_subs(&connection_pool)
|
||||
let subs_count = get_total_subs(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch total subscribers count from the database.")?;
|
||||
let max_page = get_max_page(count, SUBS_PER_PAGE);
|
||||
let max_page = get_max_page(subs_count, SUBS_PER_PAGE);
|
||||
let users = get_users(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch users")?;
|
||||
@@ -53,10 +53,10 @@ pub async fn admin_dashboard(
|
||||
.await
|
||||
.context("Could not fetch posts.")?;
|
||||
let posts_current_page = 1;
|
||||
let count = get_posts_count(&connection_pool)
|
||||
let posts_count = get_posts_count(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch posts count.")?;
|
||||
let posts_max_page = get_max_page(count, POSTS_PER_PAGE);
|
||||
let posts_max_page = get_max_page(posts_count, POSTS_PER_PAGE);
|
||||
let template = DashboardTemplate {
|
||||
user,
|
||||
idempotency_key_1,
|
||||
@@ -65,10 +65,12 @@ pub async fn admin_dashboard(
|
||||
subscribers,
|
||||
current_page,
|
||||
max_page,
|
||||
count: subs_count,
|
||||
users,
|
||||
posts,
|
||||
posts_current_page,
|
||||
posts_max_page,
|
||||
posts_count,
|
||||
};
|
||||
Ok(Html(template.render().unwrap()).into_response())
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ pub async fn delete_post(
|
||||
"We could not find the post in the database."
|
||||
)))
|
||||
} else {
|
||||
let template = MessageTemplate::success("The subscriber has been deleted.".into());
|
||||
let template = MessageTemplate::success("The post has been deleted.".into());
|
||||
Ok(template.render().unwrap().into_response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,11 +210,14 @@ pub async fn load_more(
|
||||
let posts = get_posts_page(&connection_pool, page)
|
||||
.await
|
||||
.context("Could not fetch posts from database.")?;
|
||||
let count = posts.len();
|
||||
let count = get_posts_count(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch posts count.")?;
|
||||
let max_page = get_max_page(count, POSTS_PER_PAGE);
|
||||
Ok(Html(
|
||||
PostListTemplate {
|
||||
posts,
|
||||
next_page: if count as i64 == POSTS_PER_PAGE {
|
||||
next_page: if page < max_page {
|
||||
Some(page + 1)
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -64,10 +64,12 @@ pub struct DashboardTemplate {
|
||||
pub subscribers: Vec<SubscriberEntry>,
|
||||
pub current_page: i64,
|
||||
pub max_page: i64,
|
||||
pub count: i64,
|
||||
pub users: Vec<UserEntry>,
|
||||
pub posts: Vec<PostEntry>,
|
||||
pub posts_current_page: i64,
|
||||
pub posts_max_page: i64,
|
||||
pub posts_count: i64,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
||||
Reference in New Issue
Block a user