More tests, not found page and dashboard fixes
When post was deleted, website shows a 404 page insead of an 500 page. Also made the dashboard empty page message more explicit.
This commit is contained in:
@@ -9,7 +9,7 @@ use anyhow::Context;
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
Extension, Form,
|
||||
extract::State,
|
||||
extract::{Path, State},
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use chrono::Utc;
|
||||
@@ -121,3 +121,26 @@ pub async fn create_newsletter(
|
||||
};
|
||||
insert_newsletter_issue(transaction, post_title, &template).await
|
||||
}
|
||||
|
||||
pub async fn delete_post(
|
||||
State(AppState {
|
||||
connection_pool, ..
|
||||
}): State<AppState>,
|
||||
Path(post_id): Path<Uuid>,
|
||||
) -> Result<Response, AppError> {
|
||||
let res = sqlx::query!("DELETE FROM posts WHERE post_id = $1", post_id)
|
||||
.execute(&connection_pool)
|
||||
.await
|
||||
.context("Failed to delete post from database.")
|
||||
.map_err(AppError::unexpected_message)?;
|
||||
if res.rows_affected() > 1 {
|
||||
Err(AppError::unexpected_message(anyhow::anyhow!(
|
||||
"We could not find the post in the database."
|
||||
)))
|
||||
} else {
|
||||
let template = MessageTemplate::Success {
|
||||
message: "The subscriber has been deleted.".into(),
|
||||
};
|
||||
Ok(template.render().unwrap().into_response())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user