Add query.

This commit is contained in:
LukeMathWalker 2021-07-27 09:09:20 +01:00
parent 32c03a55c5
commit 5b87b2449d

View file

@ -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<BodyData>) -> 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<Vec<ConfirmedSubscriber>, anyhow::Error> {
let rows = sqlx::query_as!(
ConfirmedSubscriber,
r#"
SELECT email, name
FROM subscriptions
WHERE status = 'confirmed'
"#,
)
.fetch_all(pool)
.await?;
Ok(rows)
}