Skip to content

Commit

Permalink
dev: fix clippy warnings for: src/mailer.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed May 10, 2023
1 parent 3e7a917 commit b737f10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use crate::cache::image::manager::ImageCacheService;
use crate::common::AppData;
use crate::config::Configuration;
use crate::databases::database;
use crate::mailer::MailerService;
use crate::routes;
use crate::tracker::service::Service;
use crate::tracker::statistics_importer::StatisticsImporter;
use crate::{mailer, routes};

pub struct Running {
pub api_server: Server,
Expand Down Expand Up @@ -48,7 +47,7 @@ pub async fn run(configuration: Configuration) -> Running {
let tracker_service = Arc::new(Service::new(cfg.clone(), database.clone()).await);
let tracker_statistics_importer =
Arc::new(StatisticsImporter::new(cfg.clone(), tracker_service.clone(), database.clone()).await);
let mailer_service = Arc::new(MailerService::new(cfg.clone()).await);
let mailer_service = Arc::new(mailer::Service::new(cfg.clone()).await);
let image_cache_service = Arc::new(ImageCacheService::new(cfg.clone()).await);

// Build app container
Expand Down
6 changes: 3 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::auth::AuthorizationService;
use crate::cache::image::manager::ImageCacheService;
use crate::config::Configuration;
use crate::databases::database::Database;
use crate::mailer::MailerService;
use crate::mailer;
use crate::tracker::service::Service;
use crate::tracker::statistics_importer::StatisticsImporter;

Expand All @@ -18,7 +18,7 @@ pub struct AppData {
pub auth: Arc<AuthorizationService>,
pub tracker_service: Arc<Service>,
pub tracker_statistics_importer: Arc<StatisticsImporter>,
pub mailer: Arc<MailerService>,
pub mailer: Arc<mailer::Service>,
pub image_cache_manager: Arc<ImageCacheService>,
}

Expand All @@ -29,7 +29,7 @@ impl AppData {
auth: Arc<AuthorizationService>,
tracker_service: Arc<Service>,
tracker_statistics_importer: Arc<StatisticsImporter>,
mailer: Arc<MailerService>,
mailer: Arc<mailer::Service>,
image_cache_manager: Arc<ImageCacheService>,
) -> AppData {
AppData {
Expand Down
18 changes: 13 additions & 5 deletions src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::config::Configuration;
use crate::errors::ServiceError;
use crate::utils::clock::current_time;

pub struct MailerService {
pub struct Service {
cfg: Arc<Configuration>,
mailer: Arc<Mailer>,
}
Expand All @@ -30,8 +30,8 @@ struct VerifyTemplate {
verification_url: String,
}

impl MailerService {
pub async fn new(cfg: Arc<Configuration>) -> MailerService {
impl Service {
pub async fn new(cfg: Arc<Configuration>) -> Service {
let mailer = Arc::new(Self::get_mailer(&cfg).await);

Self { cfg, mailer }
Expand All @@ -57,6 +57,11 @@ impl MailerService {
}
}

/// Send Verification Email
///
/// # Errors
///
/// This function will return an error if unable to send an email.
pub async fn send_verification_mail(
&self,
to: &str,
Expand Down Expand Up @@ -96,10 +101,13 @@ impl MailerService {
.singlepart(
SinglePart::builder()
.header(lettre::message::header::ContentType::TEXT_HTML)
.body(ctx.render_once().unwrap()),
.body(
ctx.render_once()
.expect("value `ctx` must have some internal error passed into it"),
),
),
)
.unwrap();
.expect("the `multipart` builder had an error");

match self.mailer.send(mail).await {
Ok(_res) => Ok(()),
Expand Down

0 comments on commit b737f10

Please sign in to comment.