Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KavikaPalletenne committed Dec 2, 2024
1 parent 5a163d3 commit 07680cc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions backend/server/src/handler/offer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::models::app::AppState;
use crate::models::auth::{OfferAdmin, OfferRecipient};
use crate::models::error::ChaosError;
use crate::models::offer::{Offer, OfferReply};
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 {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl OfferHandler {
mut transaction: DBTransaction<'_>,
Path(id): Path<i64>,
_user: OfferAdmin,
State(state): State<AppState>
State(state): State<AppState>,
) -> Result<impl IntoResponse, ChaosError> {
Offer::send_offer(id, &mut transaction.tx, state.email_credentials).await?;
transaction.tx.commit().await?;
Expand Down
2 changes: 1 addition & 1 deletion backend/server/src/models/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand Down
28 changes: 20 additions & 8 deletions backend/server/src/models/email.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -32,15 +34,25 @@ impl ChaosEmail {

EmailCredentials {
credentials: Credentials::new(smtp_username, smtp_password),
email_host
email_host,
}
}

fn new_connection(credentials: EmailCredentials) -> Result<AsyncSmtpTransport<Tokio1Executor>, ChaosError> {
Ok(AsyncSmtpTransport::relay(&*credentials.email_host)?.credentials(credentials.credentials).build())
fn new_connection(
credentials: EmailCredentials,
) -> Result<AsyncSmtpTransport<Tokio1Executor>, 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 <[email protected]>".parse()?)
.reply_to("[email protected]".parse()?)
Expand All @@ -53,4 +65,4 @@ impl ChaosEmail {

Ok(())
}
}
}
9 changes: 2 additions & 7 deletions backend/server/src/models/email_template.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::models::email::EmailParts;
use crate::models::error::ChaosError;
use chrono::{DateTime, Local, Utc};
use handlebars::Handlebars;
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:
Expand Down Expand Up @@ -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 })
}
}
2 changes: 1 addition & 1 deletion backend/server/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,4 +14,3 @@ pub mod role;
pub mod storage;
pub mod transaction;
pub mod user;
pub mod email;
11 changes: 9 additions & 2 deletions backend/server/src/models/offer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::models::email::{ChaosEmail, EmailCredentials, EmailParts};
use crate::models::email_template::EmailTemplate;
use crate::models::error::ChaosError;
use chrono::{DateTime, Utc};
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 {
Expand Down Expand Up @@ -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(())
}
}

0 comments on commit 07680cc

Please sign in to comment.