Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Redirect to /admin/newsletters after sending newsletter
Browse files Browse the repository at this point in the history
  • Loading branch information
0rzech committed Apr 12, 2024
1 parent 0ccedba commit b15fdf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/routes/admin/newsletters/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ use crate::{
utils::{e500, HttpError},
};
use anyhow::Context;
use axum::{extract::State, Form};
use axum::{extract::State, response::Redirect, Form};
use axum_messages::Messages;
use serde::Deserialize;
use sqlx::PgPool;

#[tracing::instrument(skip(app_state, form))]
pub(in crate::routes::admin) async fn publish_newsletter(
State(app_state): State<AppState>,
messages: Messages,
Form(form): Form<FormData>,
) -> Result<(), HttpError<anyhow::Error>> {
) -> Result<Redirect, HttpError<anyhow::Error>> {
for subscriber in get_confirmed_subscribers(&app_state.db_pool)
.await
.map_err(e500)?
Expand All @@ -38,7 +40,9 @@ pub(in crate::routes::admin) async fn publish_newsletter(
}
}

Ok(())
messages.info("Newsletter sent!");

Ok(Redirect::to("/admin/newsletters"))
}

#[tracing::instrument(skip(db_pool))]
Expand Down
4 changes: 2 additions & 2 deletions tests/api/admin_newsletters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn newsletters_are_delivered_to_confirmed_subscribers() {
let response = app.post_newsletters(newsletter_request_body).await;

// then
assert_eq!(response.status(), 200);
assert_redirect_to(&response, "/admin/newsletters");
}

#[tokio::test]
Expand Down Expand Up @@ -69,7 +69,7 @@ async fn newsletters_are_not_delivered_to_unconfirmed_subscribers() {
let response = app.post_newsletters(newsletter_request_body).await;

// then
assert_eq!(response.status(), 200);
assert_redirect_to(&response, "/admin/newsletters");
}

#[tokio::test]
Expand Down

0 comments on commit b15fdf5

Please sign in to comment.