Admin can now write posts

Posts can be displayed on the website. Subscribers are automatically
notified by email. This gives the opportunity to track explicitly how
many people followed the link provided in the emails sent without being
intrusive (no invisible image).
This commit is contained in:
Alphonse Paix
2025-09-18 17:22:33 +02:00
parent 848fd621b7
commit 066c2b8252
11 changed files with 284 additions and 69 deletions

View File

@@ -48,7 +48,7 @@ pub async fn insert_newsletter_issue(
}
#[tracing::instrument(skip_all)]
async fn enqueue_delivery_tasks(
pub async fn enqueue_delivery_tasks(
transaction: &mut Transaction<'static, Postgres>,
newsletter_issue_id: Uuid,
) -> Result<(), sqlx::Error> {
@@ -76,9 +76,7 @@ pub async fn publish_newsletter(
Extension(AuthenticatedUser { user_id, .. }): Extension<AuthenticatedUser>,
Form(form): Form<BodyData>,
) -> Result<Response, AdminError> {
if let Err(e) = validate_form(&form) {
return Err(AdminError::Publish(anyhow::anyhow!(e)));
}
validate_form(&form).map_err(|e| AdminError::Publish(anyhow::anyhow!(e)))?;
let idempotency_key: IdempotencyKey = form
.idempotency_key
@@ -94,11 +92,11 @@ pub async fn publish_newsletter(
let issue_id = insert_newsletter_issue(&mut transaction, &form.title, &form.text, &form.html)
.await
.context("Failed to store newsletter issue details")?;
.context("Failed to store newsletter issue details.")?;
enqueue_delivery_tasks(&mut transaction, issue_id)
.await
.context("Failed to enqueue delivery tasks")?;
.context("Failed to enqueue delivery tasks.")?;
let success_message = format!(
r#"The newsletter issue "{}" has been published!"#,