Skip to content

Commit

Permalink
refactor: general feature (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzyct authored Aug 21, 2024
1 parent 45ed737 commit 4588f42
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/core/config/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use actix_web::web;

use crate::{
features::{auth::auth_controller, general::general_controller, user::user_controller},
utils::{handler::route_not_found, health_checker},
utils::handler::route_not_found,
};

pub fn config_services(cfg: &mut web::ServiceConfig) {
Expand All @@ -13,11 +13,11 @@ pub fn config_services(cfg: &mut web::ServiceConfig) {
web::scope("/general")
.service(
web::resource("/send_email")
.route(web::post().to(general_controller::test_email)),
.route(web::post().to(general_controller::mail_sender_controller)),
)
.service(
web::resource("/health_checker")
.route(web::get().to(health_checker::health_checker)),
.route(web::get().to(general_controller::health_checker_controller)),
),
)
.service(
Expand Down
21 changes: 0 additions & 21 deletions src/features/general/domain/usecase/dto.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ use dotenv_codegen::dotenv;
use reqwest::Client;
use serde_json::json;

use crate::camel_case_struct;
use crate::core::{error::APIError, types::AppResult};
use crate::features::general::domain::usecase::dto::SendEmailParams;

camel_case_struct!(SendEmailParams {
#[validate(
required(message = "field is required"),
length(min = 1, message = "Can't be empty"),
)]
email: Option<String>,
#[validate(
required(message = "field is required"),
length(min = 1, message = "Can't be empty"),
)]
name: Option<String>,
#[validate(
required(message = "field is required"),
length(min = 1, message = "Can't be empty"),
)]
subject: Option<String>,
text_content: Option<String>,
html_content: Option<String>
});

pub async fn send_email(params: SendEmailParams) -> AppResult<String> {
let client = Client::new();
Expand Down
2 changes: 1 addition & 1 deletion src/features/general/domain/usecase/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod dto;
pub mod mail_sender;
10 changes: 7 additions & 3 deletions src/features/general/general_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use validator::Validate;

use crate::{
core::{error::APIError, middlewares::general::GeneralMiddleware},
features::general::domain::usecase::dto::SendEmailParams,
features::general::domain::usecase::mail_sender::SendEmailParams,
};
use crate::{
core::{middlewares::state::AppState, response::ResponseBody, types::AppResult},
utils::mail_sender::send_email,
features::general::domain::usecase::mail_sender::send_email,
};

pub async fn test_email(
pub async fn mail_sender_controller(
_middleware: GeneralMiddleware,
_state: web::Data<AppState>,
params: Json<SendEmailParams>,
Expand All @@ -25,3 +25,7 @@ pub async fn test_email(
.await
.map(|message| ResponseBody::<()>::success_with_message(None, message.as_str()).into())
}

pub async fn health_checker_controller(_: GeneralMiddleware) -> AppResult<HttpResponse> {
Ok(ResponseBody::<()>::success(None).into())
}
9 changes: 0 additions & 9 deletions src/utils/health_checker.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pub mod handler;
pub mod health_checker;
pub mod macros;
pub mod mail_sender;

0 comments on commit 4588f42

Please sign in to comment.