mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-11-15 21:21:00 +00:00
Send static confirmation email.
This commit is contained in:
parent
f4b066b487
commit
310ffb01a5
1 changed files with 12 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::domain::{NewSubscriber, SubscriberEmail, SubscriberName};
|
||||
use crate::email_client::EmailClient;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use chrono::Utc;
|
||||
use sqlx::PgPool;
|
||||
|
@ -23,7 +24,7 @@ impl TryInto<NewSubscriber> for FormData {
|
|||
|
||||
#[tracing::instrument(
|
||||
name = "Adding a new subscriber",
|
||||
skip(form, pool),
|
||||
skip(form, pool, email_client),
|
||||
fields(
|
||||
email = %form.email,
|
||||
name = %form.name
|
||||
|
@ -32,6 +33,7 @@ impl TryInto<NewSubscriber> for FormData {
|
|||
pub async fn subscribe(
|
||||
form: web::Form<FormData>,
|
||||
pool: web::Data<PgPool>,
|
||||
email_client: web::Data<EmailClient>,
|
||||
) -> Result<HttpResponse, HttpResponse> {
|
||||
let new_subscriber = form
|
||||
.0
|
||||
|
@ -40,6 +42,15 @@ pub async fn subscribe(
|
|||
insert_subscriber(&pool, &new_subscriber)
|
||||
.await
|
||||
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
||||
// We are swallowing the error for the time being.
|
||||
let _ = email_client
|
||||
.send_email(
|
||||
new_subscriber.email,
|
||||
"Welcome!",
|
||||
"Welcome to our newsletter!",
|
||||
"Welcome to our newsletter!",
|
||||
)
|
||||
.await;
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue