feat: actually send email
This commit is contained in:
parent
6dfc9a0f3e
commit
0427df8656
3 changed files with 51 additions and 12 deletions
|
|
@ -30,6 +30,7 @@ impl TryFrom<FormData> for NewSubscriber {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: remove request_id?
|
||||
#[tracing::instrument(
|
||||
name = "Adding a new subscriber",
|
||||
skip(form, db_pool, email_client),
|
||||
|
|
@ -52,14 +53,22 @@ pub async fn subscribe(
|
|||
return (StatusCode::BAD_REQUEST, "Invalid subscription.").into_response();
|
||||
}
|
||||
};
|
||||
match insert_subscriber(&db_pool, &new_subscriber).await {
|
||||
Ok(_) => {
|
||||
return (StatusCode::OK,).into_response();
|
||||
}
|
||||
Err(_) => {
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, "Something went wrong.").into_response();
|
||||
}
|
||||
if insert_subscriber(&db_pool, &new_subscriber).await.is_err() {
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, "Something went wrong.").into_response();
|
||||
}
|
||||
if email_client
|
||||
.send_email(
|
||||
new_subscriber.email,
|
||||
"Welcome!",
|
||||
"Welcome to our newsletter!",
|
||||
"Welcome to our newsletter!",
|
||||
)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, "Something went wrong.").into_response();
|
||||
}
|
||||
return (StatusCode::OK,).into_response();
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue