Skip to content

Commit

Permalink
Format Rust code using rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Sep 29, 2023
1 parent dadcb71 commit 5f25e28
Show file tree
Hide file tree
Showing 61 changed files with 256 additions and 244 deletions.
10 changes: 4 additions & 6 deletions src/api/admin_user/admin_user_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ use super::handlers::{
authenticate_admin_user_handler::authenticate_admin_user_handler,
create_admin_user_handler::create_admin_user_handler, create_role_handler::create_role_handler,
dashboard_handler::dashboard_handler, delete_admin_user_handler::delete_admin_user_handler,
edit_admin_user_handler::edit_admin_user_handler, edit_role_handler::edit_role_handler,
role_table_handler::role_table_handler, show_admin_user_handler::show_admin_user_handler,
delete_role_handler::delete_role_handler, edit_admin_user_handler::edit_admin_user_handler,
edit_role_handler::edit_role_handler, role_table_handler::role_table_handler,
show_admin_user_handler::show_admin_user_handler, show_role_handler::show_role_handler,
store_admin_user_handler::store_admin_user_handler, store_role_handler::store_role_handler,
update_admin_user_handler::update_admin_user_handler,
update_role_handler::update_role_handler,
show_role_handler::show_role_handler,
delete_role_handler::delete_role_handler,
update_admin_user_handler::update_admin_user_handler, update_role_handler::update_role_handler,
};

pub fn admin_user_routes(state: Arc<AvoRedState>) -> Router {
Expand Down
8 changes: 6 additions & 2 deletions src/api/admin_user/handlers/create_role_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub async fn create_role_handler(
session.remove("validation_error_name");
session.remove("validation_error_identifier");

let view_model = CreateRoleViewModel { logged_in_user, validation_name_message, validation_identifier_message };
let view_model = CreateRoleViewModel {
logged_in_user,
validation_name_message,
validation_identifier_message,
};

let handlebars = &state.handlebars;
let html = handlebars
Expand All @@ -43,5 +47,5 @@ pub async fn create_role_handler(
pub struct CreateRoleViewModel {
pub logged_in_user: RoleModel,
pub validation_name_message: String,
pub validation_identifier_message: String
pub validation_identifier_message: String,
}
7 changes: 5 additions & 2 deletions src/api/admin_user/handlers/delete_admin_user_handler.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
use std::sync::Arc;

use crate::providers::avored_view_provider::translate;
use crate::{
avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession,
};
use axum::{
extract::{Path, State},
response::{IntoResponse, Redirect},
};
use crate::providers::avored_view_provider::translate;

pub async fn delete_admin_user_handler(
mut session: AvoRedSession,
Path(admin_user_id): Path<String>,
state: State<Arc<AvoRedState>>,
) -> Result<impl IntoResponse> {
println!("->> {:<12} - delete_admin_user_handler", "HANDLER");
state.admin_user_service.delete_admin_user(&state.db, admin_user_id).await?;
state
.admin_user_service
.delete_admin_user(&state.db, admin_user_id)
.await?;

session
.insert("success_message", translate("success_deleted_admin_user"))
Expand Down
2 changes: 1 addition & 1 deletion src/api/admin_user/handlers/delete_role_handler.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::sync::Arc;

use crate::providers::avored_view_provider::translate;
use crate::{
avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession,
};
use axum::{
extract::{Path, State},
response::{IntoResponse, Redirect},
};
use crate::providers::avored_view_provider::translate;

pub async fn delete_role_handler(
mut session: AvoRedSession,
Expand Down
6 changes: 4 additions & 2 deletions src/api/admin_user/handlers/edit_admin_user_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ pub async fn edit_admin_user_handler(

let view_model = EditAdminUserHandlerViewModel {
logged_in_user,
admin_user_model
admin_user_model,
};

// let admin_user_model = state.ad`

let handlebars = &state.handlebars;
let html = handlebars
.render("admin-user/edit-admin-user", &view_model)
.expect("there is an issue with handlerbar rendering admin-user/edit-admin-user.hbs template");
.expect(
"there is an issue with handlerbar rendering admin-user/edit-admin-user.hbs template",
);

Ok(Html(html))
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/admin_user/handlers/edit_role_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pub async fn edit_role_handler(
};

let role_model = state.role_service.find_by_id(&state.db, role_id).await?;

let mut view_model = EditRoleViewModel::default();
view_model.logged_in_user = logged_in_user;
view_model.role_model = role_model.clone();

let handlebars = &state.handlebars;
let html = handlebars
.render("admin-user/edit-role", &view_model)
Expand Down
20 changes: 10 additions & 10 deletions src/api/admin_user/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pub mod admin_login_handler;
pub mod authenticate_admin_user_handler;
pub mod dashboard_handler;
pub mod admin_user_table_handler;
pub mod authenticate_admin_user_handler;
pub mod create_admin_user_handler;
pub mod store_admin_user_handler;
pub mod edit_admin_user_handler;
pub mod update_admin_user_handler;
pub mod show_admin_user_handler;
pub mod create_role_handler;
pub mod dashboard_handler;
pub mod delete_admin_user_handler;
pub mod delete_role_handler;
pub mod edit_admin_user_handler;
pub mod edit_role_handler;
pub mod role_table_handler;
pub mod create_role_handler;
pub mod show_admin_user_handler;
pub mod show_role_handler;
pub mod store_admin_user_handler;
pub mod store_role_handler;
pub mod edit_role_handler;
pub mod update_admin_user_handler;
pub mod update_role_handler;
pub mod show_role_handler;
pub mod delete_role_handler;
4 changes: 2 additions & 2 deletions src/api/admin_user/handlers/role_table_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub async fn role_table_handler(
let role_pagination = state.role_service.paginate(&state.db, current_page).await?;
let success_message = session.get("success_message").unwrap_or(String::from(""));
session.remove("success_message");

let view_model = RoleViewModel {
logged_in_user,
role_pagination,
success_message
success_message,
};

let handlebars = &state.handlebars;
Expand Down
4 changes: 3 additions & 1 deletion src/api/admin_user/handlers/show_admin_user_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ pub async fn show_admin_user_handler(
let handlebars = &state.handlebars;
let html = handlebars
.render("admin-user/show-admin-user", &view_model)
.expect("there is an issue with handlerbar rendering admin-user/show-admin-user.hbs template");
.expect(
"there is an issue with handlerbar rendering admin-user/show-admin-user.hbs template",
);

Ok(Html(html))
}
Expand Down
9 changes: 4 additions & 5 deletions src/api/admin_user/handlers/show_role_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::sync::Arc;

use crate::{
avored_state::AvoRedState, error::Result, models::{admin_user_model::AdminUserModel, role_model::RoleModel},
avored_state::AvoRedState,
error::Result,
models::{admin_user_model::AdminUserModel, role_model::RoleModel},
providers::avored_session_provider::AvoRedSession,
};
use axum::{
Expand All @@ -21,10 +23,7 @@ pub async fn show_role_handler(
None => AdminUserModel::default(),
};

let role_model = state
.role_service
.find_by_id(&state.db, role_id)
.await?;
let role_model = state.role_service.find_by_id(&state.db, role_id).await?;

let view_model = ShowRoleViewModel {
logged_in_user,
Expand Down
10 changes: 4 additions & 6 deletions src/api/admin_user/handlers/store_admin_user_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{path::Path, sync::Arc};

use crate::providers::avored_view_provider::translate;
use crate::{
api::admin_user::requests::store_admin_user_request::StoreAdminUserRequest,
avored_state::AvoRedState,
Expand All @@ -14,7 +15,6 @@ use axum::{
};
use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};
use urlencoding::decode_binary;
use crate::providers::avored_view_provider::translate;

pub async fn store_admin_user_handler(
state: State<Arc<AvoRedState>>,
Expand Down Expand Up @@ -48,19 +48,17 @@ pub async fn store_admin_user_handler(
let _file_content_type = field.content_type().unwrap().to_string();
let file_name = field.file_name().unwrap().to_string();
let data = field.bytes().await.unwrap();

if !file_name.is_empty() {

if !file_name.is_empty() {
let file_ext = file_name.split(".").last().unwrap_or(".png");
let new_file_name = format!("{}.{}", s, file_ext);

let file_name = Path::new(&new_file_name).file_name().unwrap();

profile_image = format!("upload/{}", new_file_name);
let full_path = Path::new("public").join("upload").join(file_name);
tokio::fs::write(full_path, data).await.unwrap();
}

}
"full_name" => {
let bytes = field.bytes().await.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/api/admin_user/handlers/store_role_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use crate::providers::avored_view_provider::translate;
use crate::{
api::admin_user::requests::store_role_request::StoreRoleRequest,
avored_state::AvoRedState,
Expand All @@ -13,7 +14,6 @@ use axum::{
response::{IntoResponse, Redirect},
};
use validator::HasLen;
use crate::providers::avored_view_provider::translate;

pub async fn store_role_handler(
state: State<Arc<AvoRedState>>,
Expand All @@ -28,14 +28,14 @@ pub async fn store_role_handler(
if validation_error_list.errors().length() > 0 {
return Ok(Redirect::to("/admin/create-role").into_response());
}

let creatable_role = CreatableRole {
name: payload.name,
identifier: payload.identifier,
permissions: payload.permissions,
logged_in_username: logged_in_user.email,
};

let _created_role = state
.role_service
.create_role(&state.db, creatable_role)
Expand Down
11 changes: 5 additions & 6 deletions src/api/admin_user/handlers/update_admin_user_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{path::Path, sync::Arc};

use crate::providers::avored_view_provider::translate;
use crate::{
api::admin_user::requests::update_admin_user_request::UpdateAdminUserRequest,
avored_state::AvoRedState,
Expand All @@ -13,7 +14,6 @@ use axum::{
};
use rand::{distributions::Alphanumeric, Rng};
use urlencoding::decode_binary;
use crate::providers::avored_view_provider::translate;

pub async fn update_admin_user_handler(
mut session: AvoRedSession,
Expand Down Expand Up @@ -47,14 +47,13 @@ pub async fn update_admin_user_handler(
let _file_content_type = field.content_type().unwrap().to_string();
let file_name = field.file_name().unwrap().to_string();
let data = field.bytes().await.unwrap();

if !file_name.is_empty() {

if !file_name.is_empty() {
let file_ext = file_name.split(".").last().unwrap_or(".png");
let new_file_name = format!("{}.{}", s, file_ext);

let file_name = Path::new(&new_file_name).file_name().unwrap();

profile_image = format!("upload/{}", new_file_name);
let full_path = Path::new("public").join("upload").join(file_name);
tokio::fs::write(full_path, data).await.unwrap();
Expand Down Expand Up @@ -115,7 +114,7 @@ pub async fn update_admin_user_handler(
.admin_user_service
.update_admin_user(&state.db, updateable_admin_user_model)
.await?;

session
.insert("success_message", translate("success_updated_admin_user"))
.expect("Could not store the success message into session.");
Expand Down
4 changes: 2 additions & 2 deletions src/api/admin_user/handlers/update_role_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use crate::providers::avored_view_provider::translate;
use crate::{
api::admin_user::requests::update_role_request::UpdateRoleRequest,
avored_state::AvoRedState,
Expand All @@ -13,7 +14,6 @@ use axum::{
response::{IntoResponse, Redirect},
};
use validator::HasLen;
use crate::providers::avored_view_provider::translate;

pub async fn update_role_handler(
mut session: AvoRedSession,
Expand All @@ -39,7 +39,7 @@ pub async fn update_role_handler(
name: payload.name,
identifier: payload.identifier,
logged_in_username: logged_in_user.email,
permissions: payload.permissions
permissions: payload.permissions,
};
let _role_model = state
.role_service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub struct AuthenticateAdminUserRequest {
pub password: String,
}


impl AuthenticateAdminUserRequest {
pub fn validate_errors(&self, mut session: AvoRedSession) -> Result<ValidationErrors> {
let validation_error_list = match self.validate() {
Expand Down
6 changes: 3 additions & 3 deletions src/api/admin_user/requests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod admin_user_table_query;
pub mod authenticate_admin_user_request;
pub mod role_table_query;
pub mod store_admin_user_request;
pub mod update_admin_user_request;
pub mod store_role_request;
pub mod update_admin_user_request;
pub mod update_role_request;
pub mod admin_user_table_query;
pub mod role_table_query;
7 changes: 3 additions & 4 deletions src/api/admin_user/requests/store_role_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::Result;
use serde::Deserialize;
use validator::{Validate, ValidationErrors, ValidationErrorsKind};
use crate::error::Result;

use crate::providers::avored_session_provider::AvoRedSession;

Expand All @@ -12,10 +12,9 @@ pub struct StoreRoleRequest {
#[validate(length(min = 1, message = "The identifier is a required field."))]
pub identifier: String,

pub permissions: Vec<String>
pub permissions: Vec<String>,
}


#[derive(Deserialize, Debug, Clone, Validate, Default)]
pub struct Permission {
pub dashboard: Option<bool>,
Expand All @@ -25,7 +24,7 @@ pub struct Permission {
pub role_table: Option<bool>,
pub role_create: Option<bool>,
pub role_update: Option<bool>,
pub role_delete: Option<bool>
pub role_delete: Option<bool>,
}

impl StoreRoleRequest {
Expand Down
2 changes: 1 addition & 1 deletion src/api/admin_user/requests/update_admin_user_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use serde::Deserialize;
#[derive(Deserialize, Debug, Clone)]
pub struct UpdateAdminUserRequest {
pub full_name: String,
pub is_super_admin: bool
pub is_super_admin: bool,
}
Loading

0 comments on commit 5f25e28

Please sign in to comment.