Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony M. Bonafide <AnthonyMBonafide@gmail.com>
  • Loading branch information
AnthonyMBonafide committed Apr 4, 2024
1 parent 7727206 commit d0889a5
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/routes/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ pub struct FormData {

#[tracing::instrument(
name="Adding a new subscriber",
skip(form,connection),
fields(
skip(form,connection),
fields(
subscriber_email = %form.email,
subscriber_name = %form.name
)
)]
pub async fn subscribe(form: web::Form<FormData>, connection: web::Data<PgPool>) -> HttpResponse {

match insert_subscriber(&connection, &form).await{
Ok(_) => HttpResponse::Ok().finish(),
Err(_) => HttpResponse::InternalServerError().finish(),
match insert_subscriber(&connection, &form).await {
Ok(_) => HttpResponse::Ok().finish(),
Err(_) => HttpResponse::InternalServerError().finish(),
}
}

#[tracing::instrument(
name="Saving new subscriber details in the database",
skip(form,pool),
fields(
skip(form,pool),
fields(
subscriber_email = %form.email,
subscriber_name = %form.name
)
)]

pub async fn insert_subscriber(pool: &PgPool, form: &FormData) ->Result<(),sqlx::error::Error> {
sqlx::query!(
pub async fn insert_subscriber(pool: &PgPool, form: &FormData) -> Result<(), sqlx::error::Error> {
sqlx::query!(
r#"
INSERT INTO subscriptions (id, email, name, subscribed_at)
VALUES ($1, $2, $3, $4)
Expand All @@ -45,10 +44,12 @@ sqlx::query!(
form.name,
Utc::now()
)
.execute(pool).await.map_err(|e| {
tracing::error!("Failed to execute query: {:?}", e);
e
})?;
.execute(pool)
.await
.map_err(|e| {
tracing::error!("Failed to execute query: {:?}", e);
e
})?;

Ok(())
}

0 comments on commit d0889a5

Please sign in to comment.