Refactor admin routes to use new AppError struct in responses
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
authentication::AuthenticatedUser,
|
||||
idempotency::{IdempotencyKey, save_response, try_processing},
|
||||
routes::AdminError,
|
||||
routes::{AdminError, AppError},
|
||||
startup::AppState,
|
||||
templates::MessageTemplate,
|
||||
};
|
||||
@@ -75,7 +75,7 @@ pub async fn publish_newsletter(
|
||||
}): State<AppState>,
|
||||
Extension(AuthenticatedUser { user_id, .. }): Extension<AuthenticatedUser>,
|
||||
Form(form): Form<BodyData>,
|
||||
) -> Result<Response, AdminError> {
|
||||
) -> Result<Response, AppError> {
|
||||
validate_form(&form).map_err(|e| AdminError::Publish(anyhow::anyhow!(e)))?;
|
||||
|
||||
let idempotency_key: IdempotencyKey = form
|
||||
@@ -104,9 +104,10 @@ pub async fn publish_newsletter(
|
||||
);
|
||||
let template = MessageTemplate::Success { message };
|
||||
let response = Html(template.render().unwrap()).into_response();
|
||||
save_response(transaction, &idempotency_key, user_id, response)
|
||||
let response = save_response(transaction, &idempotency_key, user_id, response)
|
||||
.await
|
||||
.map_err(AdminError::UnexpectedError)
|
||||
.map_err(AdminError::UnexpectedError)?;
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn validate_form(form: &BodyData) -> Result<(), &'static str> {
|
||||
|
||||
Reference in New Issue
Block a user