mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-12-17 21:46:40 +00:00
Add query.
This commit is contained in:
parent
32c03a55c5
commit
5b87b2449d
1 changed files with 23 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue