From 07680ccbc9e4ab82c7b836b2c038900dd951a9aa Mon Sep 17 00:00:00 2001 From: Kavika Date: Mon, 2 Dec 2024 23:29:56 +1100 Subject: [PATCH] cargo fmt --- backend/server/src/handler/offer.rs | 4 +-- backend/server/src/models/app.rs | 2 +- backend/server/src/models/email.rs | 28 +++++++++++++++------ backend/server/src/models/email_template.rs | 9 ++----- backend/server/src/models/mod.rs | 2 +- backend/server/src/models/offer.rs | 11 ++++++-- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/backend/server/src/handler/offer.rs b/backend/server/src/handler/offer.rs index b73e4438..09ea3472 100644 --- a/backend/server/src/handler/offer.rs +++ b/backend/server/src/handler/offer.rs @@ -1,3 +1,4 @@ +use crate::models::app::AppState; use crate::models::auth::{OfferAdmin, OfferRecipient}; use crate::models::error::ChaosError; use crate::models::offer::{Offer, OfferReply}; @@ -5,7 +6,6 @@ use crate::models::transaction::DBTransaction; use axum::extract::{Json, Path, State}; use axum::http::StatusCode; use axum::response::IntoResponse; -use crate::models::app::AppState; pub struct OfferHandler; impl OfferHandler { @@ -58,7 +58,7 @@ impl OfferHandler { mut transaction: DBTransaction<'_>, Path(id): Path, _user: OfferAdmin, - State(state): State + State(state): State, ) -> Result { Offer::send_offer(id, &mut transaction.tx, state.email_credentials).await?; transaction.tx.commit().await?; diff --git a/backend/server/src/models/app.rs b/backend/server/src/models/app.rs index efebced5..f4114db8 100644 --- a/backend/server/src/models/app.rs +++ b/backend/server/src/models/app.rs @@ -9,6 +9,7 @@ use crate::handler::question::QuestionHandler; use crate::handler::rating::RatingHandler; use crate::handler::role::RoleHandler; use crate::handler::user::UserHandler; +use crate::models::email::{ChaosEmail, EmailCredentials}; use crate::models::error::ChaosError; use crate::models::storage::Storage; use axum::routing::{get, patch, post}; @@ -20,7 +21,6 @@ use snowflake::SnowflakeIdGenerator; use sqlx::postgres::PgPoolOptions; use sqlx::{Pool, Postgres}; use std::env; -use crate::models::email::{ChaosEmail, EmailCredentials}; #[derive(Clone)] pub struct AppState { diff --git a/backend/server/src/models/email.rs b/backend/server/src/models/email.rs index 023ff516..b42d843a 100644 --- a/backend/server/src/models/email.rs +++ b/backend/server/src/models/email.rs @@ -1,7 +1,9 @@ -use std::env; -use lettre::{AsyncSmtpTransport, AsyncTransport, Message, SmtpTransport, Tokio1Executor, Transport}; -use lettre::transport::smtp::authentication::Credentials; use crate::models::error::ChaosError; +use lettre::transport::smtp::authentication::Credentials; +use lettre::{ + AsyncSmtpTransport, AsyncTransport, Message, SmtpTransport, Tokio1Executor, Transport, +}; +use std::env; pub struct ChaosEmail; @@ -32,15 +34,25 @@ impl ChaosEmail { EmailCredentials { credentials: Credentials::new(smtp_username, smtp_password), - email_host + email_host, } } - fn new_connection(credentials: EmailCredentials) -> Result, ChaosError> { - Ok(AsyncSmtpTransport::relay(&*credentials.email_host)?.credentials(credentials.credentials).build()) + fn new_connection( + credentials: EmailCredentials, + ) -> Result, ChaosError> { + Ok(AsyncSmtpTransport::relay(&*credentials.email_host)? + .credentials(credentials.credentials) + .build()) } - pub async fn send_message(recipient_name: String, recipient_email_address: String, subject: String, body: String, credentials: EmailCredentials) -> Result<(), ChaosError> { + pub async fn send_message( + recipient_name: String, + recipient_email_address: String, + subject: String, + body: String, + credentials: EmailCredentials, + ) -> Result<(), ChaosError> { let message = Message::builder() .from("Chaos Subcommittee Recruitment ".parse()?) .reply_to("help@chaos.devsoc.app".parse()?) @@ -53,4 +65,4 @@ impl ChaosEmail { Ok(()) } -} \ No newline at end of file +} diff --git a/backend/server/src/models/email_template.rs b/backend/server/src/models/email_template.rs index 80680b03..ecf3792e 100644 --- a/backend/server/src/models/email_template.rs +++ b/backend/server/src/models/email_template.rs @@ -1,3 +1,4 @@ +use crate::models::email::EmailParts; use crate::models::error::ChaosError; use chrono::{DateTime, Local, Utc}; use handlebars::Handlebars; @@ -5,7 +6,6 @@ use serde::{Deserialize, Serialize}; use sqlx::{Pool, Postgres, Transaction}; use std::collections::HashMap; use std::ops::DerefMut; -use crate::models::email::EmailParts; /// Email templates to update applicants /// Supported tags: @@ -115,11 +115,6 @@ impl EmailTemplate { let subject = handlebars.render("template_subject", &data)?; let body = handlebars.render("template_body", &data)?; - Ok( - EmailParts { - subject, - body - } - ) + Ok(EmailParts { subject, body }) } } diff --git a/backend/server/src/models/mod.rs b/backend/server/src/models/mod.rs index 233f1981..d1922411 100644 --- a/backend/server/src/models/mod.rs +++ b/backend/server/src/models/mod.rs @@ -3,6 +3,7 @@ pub mod app; pub mod application; pub mod auth; pub mod campaign; +pub mod email; pub mod email_template; pub mod error; pub mod offer; @@ -13,4 +14,3 @@ pub mod role; pub mod storage; pub mod transaction; pub mod user; -pub mod email; diff --git a/backend/server/src/models/offer.rs b/backend/server/src/models/offer.rs index 25c86b45..58abdae0 100644 --- a/backend/server/src/models/offer.rs +++ b/backend/server/src/models/offer.rs @@ -1,3 +1,4 @@ +use crate::models::email::{ChaosEmail, EmailCredentials, EmailParts}; use crate::models::email_template::EmailTemplate; use crate::models::error::ChaosError; use chrono::{DateTime, Utc}; @@ -5,7 +6,6 @@ use serde::{Deserialize, Serialize}; use snowflake::SnowflakeIdGenerator; use sqlx::{Postgres, Transaction}; use std::ops::DerefMut; -use crate::models::email::{ChaosEmail, EmailCredentials, EmailParts}; #[derive(Deserialize)] pub struct Offer { @@ -220,7 +220,14 @@ impl Offer { ) .await?; - ChaosEmail::send_message(offer.user_name, offer.user_email, email_parts.subject, email_parts.body, email_credentials).await?; + ChaosEmail::send_message( + offer.user_name, + offer.user_email, + email_parts.subject, + email_parts.body, + email_credentials, + ) + .await?; Ok(()) } }