mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-09-28 22:31:54 +00:00
Refactor subscribe.
This commit is contained in:
parent
bdddc29ac1
commit
3f3c73a93e
1 changed files with 20 additions and 15 deletions
|
@ -43,22 +43,27 @@ pub async fn subscribe(
|
||||||
.await
|
.await
|
||||||
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
||||||
// We are swallowing the error for the time being.
|
// We are swallowing the error for the time being.
|
||||||
|
let _ = send_confirmation_email(&email_client).await;
|
||||||
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(
|
||||||
|
name = "Send a confirmation email to a new subscriber",
|
||||||
|
skip(new_subscriber, pool)
|
||||||
|
)]
|
||||||
|
pub async fn send_confirmation_email(email_client: &EmailClient) -> Result<(), reqwest::Error> {
|
||||||
let confirmation_link = "https://my-api.com/subscriptions/confirm";
|
let confirmation_link = "https://my-api.com/subscriptions/confirm";
|
||||||
let _ = email_client
|
let plain_body = format!(
|
||||||
.send_email(
|
|
||||||
new_subscriber.email,
|
|
||||||
"Welcome!",
|
|
||||||
&format!(
|
|
||||||
"Welcome to our newsletter!<br />Click <a href=\"{}\">here</a> to confirm your subscription.",
|
|
||||||
confirmation_link
|
|
||||||
),
|
|
||||||
&format!(
|
|
||||||
"Welcome to our newsletter!\nVisit {} to confirm your subscription.",
|
"Welcome to our newsletter!\nVisit {} to confirm your subscription.",
|
||||||
confirmation_link
|
confirmation_link
|
||||||
),
|
);
|
||||||
)
|
let html_body = format!(
|
||||||
.await;
|
"Welcome to our newsletter!<br />Click <a href=\"{}\">here</a> to confirm your subscription.",
|
||||||
Ok(HttpResponse::Ok().finish())
|
confirmation_link
|
||||||
|
);
|
||||||
|
email_client
|
||||||
|
.send_email(new_subscriber.email, "Welcome!", &html_body, &plain_body)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
|
|
Loading…
Reference in a new issue