diff --git a/src/routes/newsletters.rs b/src/routes/newsletters.rs index f1c1555..0b925a3 100644 --- a/src/routes/newsletters.rs +++ b/src/routes/newsletters.rs @@ -1,4 +1,5 @@ use actix_web::{web, HttpResponse}; +use sqlx::PgPool; #[derive(serde::Deserialize)] pub struct BodyData { @@ -15,3 +16,25 @@ pub struct Content { pub async fn publish_newsletter(_body: web::Json) -> HttpResponse { HttpResponse::Ok().finish() } + +struct ConfirmedSubscriber { + name: String, + email: String, +} + +#[tracing::instrument(name = "Adding a new subscriber", skip(pool))] +async fn get_confirmed_subscribers( + pool: &PgPool, +) -> Result, anyhow::Error> { + let rows = sqlx::query_as!( + ConfirmedSubscriber, + r#" + SELECT email, name + FROM subscriptions + WHERE status = 'confirmed' + "#, + ) + .fetch_all(pool) + .await?; + Ok(rows) +}