feat: actually send email

This commit is contained in:
Sandro Eiler 2024-03-04 21:49:08 +01:00
parent 6dfc9a0f3e
commit 0427df8656
3 changed files with 51 additions and 12 deletions

View file

@ -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(