diff --git a/src/api/admin_user/admin_user_routes.rs b/src/api/admin_user/admin_user_routes.rs index 1dc51623..93ba1b4b 100644 --- a/src/api/admin_user/admin_user_routes.rs +++ b/src/api/admin_user/admin_user_routes.rs @@ -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) -> Router { diff --git a/src/api/admin_user/handlers/create_role_handler.rs b/src/api/admin_user/handlers/create_role_handler.rs index 81bfe22c..4ee86199 100644 --- a/src/api/admin_user/handlers/create_role_handler.rs +++ b/src/api/admin_user/handlers/create_role_handler.rs @@ -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 @@ -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, } diff --git a/src/api/admin_user/handlers/delete_admin_user_handler.rs b/src/api/admin_user/handlers/delete_admin_user_handler.rs index 2005ffe6..fb6f1079 100644 --- a/src/api/admin_user/handlers/delete_admin_user_handler.rs +++ b/src/api/admin_user/handlers/delete_admin_user_handler.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::providers::avored_view_provider::translate; use crate::{ avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession, }; @@ -7,7 +8,6 @@ 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, @@ -15,7 +15,10 @@ pub async fn delete_admin_user_handler( state: State>, ) -> Result { 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")) diff --git a/src/api/admin_user/handlers/delete_role_handler.rs b/src/api/admin_user/handlers/delete_role_handler.rs index 57bf82a1..e138cca5 100644 --- a/src/api/admin_user/handlers/delete_role_handler.rs +++ b/src/api/admin_user/handlers/delete_role_handler.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::providers::avored_view_provider::translate; use crate::{ avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession, }; @@ -7,7 +8,6 @@ use axum::{ extract::{Path, State}, response::{IntoResponse, Redirect}, }; -use crate::providers::avored_view_provider::translate; pub async fn delete_role_handler( mut session: AvoRedSession, diff --git a/src/api/admin_user/handlers/edit_admin_user_handler.rs b/src/api/admin_user/handlers/edit_admin_user_handler.rs index 7ce6e0b3..5829a5cd 100644 --- a/src/api/admin_user/handlers/edit_admin_user_handler.rs +++ b/src/api/admin_user/handlers/edit_admin_user_handler.rs @@ -28,7 +28,7 @@ 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` @@ -36,7 +36,9 @@ pub async fn edit_admin_user_handler( 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)) } diff --git a/src/api/admin_user/handlers/edit_role_handler.rs b/src/api/admin_user/handlers/edit_role_handler.rs index 51c245de..e6f4972a 100644 --- a/src/api/admin_user/handlers/edit_role_handler.rs +++ b/src/api/admin_user/handlers/edit_role_handler.rs @@ -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) diff --git a/src/api/admin_user/handlers/mod.rs b/src/api/admin_user/handlers/mod.rs index 71fe2ab9..4adf5253 100644 --- a/src/api/admin_user/handlers/mod.rs +++ b/src/api/admin_user/handlers/mod.rs @@ -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; diff --git a/src/api/admin_user/handlers/role_table_handler.rs b/src/api/admin_user/handlers/role_table_handler.rs index 168832c4..432d32f9 100644 --- a/src/api/admin_user/handlers/role_table_handler.rs +++ b/src/api/admin_user/handlers/role_table_handler.rs @@ -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; diff --git a/src/api/admin_user/handlers/show_admin_user_handler.rs b/src/api/admin_user/handlers/show_admin_user_handler.rs index 1be4f307..116e92e6 100644 --- a/src/api/admin_user/handlers/show_admin_user_handler.rs +++ b/src/api/admin_user/handlers/show_admin_user_handler.rs @@ -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)) } diff --git a/src/api/admin_user/handlers/show_role_handler.rs b/src/api/admin_user/handlers/show_role_handler.rs index 25d12717..4648a91a 100644 --- a/src/api/admin_user/handlers/show_role_handler.rs +++ b/src/api/admin_user/handlers/show_role_handler.rs @@ -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::{ @@ -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, diff --git a/src/api/admin_user/handlers/store_admin_user_handler.rs b/src/api/admin_user/handlers/store_admin_user_handler.rs index 518d5c0e..0fc5a5f7 100644 --- a/src/api/admin_user/handlers/store_admin_user_handler.rs +++ b/src/api/admin_user/handlers/store_admin_user_handler.rs @@ -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, @@ -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>, @@ -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(); diff --git a/src/api/admin_user/handlers/store_role_handler.rs b/src/api/admin_user/handlers/store_role_handler.rs index ab9b6b72..1c827609 100644 --- a/src/api/admin_user/handlers/store_role_handler.rs +++ b/src/api/admin_user/handlers/store_role_handler.rs @@ -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, @@ -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>, @@ -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) diff --git a/src/api/admin_user/handlers/update_admin_user_handler.rs b/src/api/admin_user/handlers/update_admin_user_handler.rs index cff3ca63..07e72606 100644 --- a/src/api/admin_user/handlers/update_admin_user_handler.rs +++ b/src/api/admin_user/handlers/update_admin_user_handler.rs @@ -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, @@ -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, @@ -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(); @@ -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."); diff --git a/src/api/admin_user/handlers/update_role_handler.rs b/src/api/admin_user/handlers/update_role_handler.rs index 7294d787..654cbaaf 100644 --- a/src/api/admin_user/handlers/update_role_handler.rs +++ b/src/api/admin_user/handlers/update_role_handler.rs @@ -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, @@ -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, @@ -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 diff --git a/src/api/admin_user/requests/authenticate_admin_user_request.rs b/src/api/admin_user/requests/authenticate_admin_user_request.rs index 3fde50b8..d9ce015f 100644 --- a/src/api/admin_user/requests/authenticate_admin_user_request.rs +++ b/src/api/admin_user/requests/authenticate_admin_user_request.rs @@ -10,7 +10,6 @@ pub struct AuthenticateAdminUserRequest { pub password: String, } - impl AuthenticateAdminUserRequest { pub fn validate_errors(&self, mut session: AvoRedSession) -> Result { let validation_error_list = match self.validate() { diff --git a/src/api/admin_user/requests/mod.rs b/src/api/admin_user/requests/mod.rs index d33eab80..0f415002 100644 --- a/src/api/admin_user/requests/mod.rs +++ b/src/api/admin_user/requests/mod.rs @@ -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; diff --git a/src/api/admin_user/requests/store_role_request.rs b/src/api/admin_user/requests/store_role_request.rs index 1ff9c3a6..0128277e 100644 --- a/src/api/admin_user/requests/store_role_request.rs +++ b/src/api/admin_user/requests/store_role_request.rs @@ -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; @@ -12,10 +12,9 @@ pub struct StoreRoleRequest { #[validate(length(min = 1, message = "The identifier is a required field."))] pub identifier: String, - pub permissions: Vec + pub permissions: Vec, } - #[derive(Deserialize, Debug, Clone, Validate, Default)] pub struct Permission { pub dashboard: Option, @@ -25,7 +24,7 @@ pub struct Permission { pub role_table: Option, pub role_create: Option, pub role_update: Option, - pub role_delete: Option + pub role_delete: Option, } impl StoreRoleRequest { diff --git a/src/api/admin_user/requests/update_admin_user_request.rs b/src/api/admin_user/requests/update_admin_user_request.rs index 49d7d164..f459e955 100644 --- a/src/api/admin_user/requests/update_admin_user_request.rs +++ b/src/api/admin_user/requests/update_admin_user_request.rs @@ -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, } diff --git a/src/api/admin_user/requests/update_role_request.rs b/src/api/admin_user/requests/update_role_request.rs index 9665010b..07b2ed17 100644 --- a/src/api/admin_user/requests/update_role_request.rs +++ b/src/api/admin_user/requests/update_role_request.rs @@ -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; @@ -12,11 +12,9 @@ pub struct UpdateRoleRequest { #[validate(length(min = 1, message = "The identifier is a required field."))] pub identifier: String, - pub permissions: Vec + pub permissions: Vec, } - - impl UpdateRoleRequest { pub fn validate_errors(&self, mut session: AvoRedSession) -> Result { let validation_error_list = match self.validate() { diff --git a/src/api/component/component_routes.rs b/src/api/component/component_routes.rs index fa718c49..32683b2e 100644 --- a/src/api/component/component_routes.rs +++ b/src/api/component/component_routes.rs @@ -1,17 +1,17 @@ use std::sync::Arc; -use axum::{middleware, routing::get, Router}; use axum::routing::post; +use axum::{middleware, routing::get, Router}; -use crate::{ - avored_state::AvoRedState, middleware::require_authentication::require_authentication, -}; use crate::api::component::handlers::create_component_handler::create_component_handler; use crate::api::component::handlers::delete_component_handler::delete_component_handler; -use crate::api::component::handlers::store_component_handler::store_component_handler; use crate::api::component::handlers::edit_component_handler::edit_component_handler; use crate::api::component::handlers::show_component_handler::show_component_handler; +use crate::api::component::handlers::store_component_handler::store_component_handler; use crate::api::component::handlers::update_component_handler::update_component_handler; +use crate::{ + avored_state::AvoRedState, middleware::require_authentication::require_authentication, +}; use super::handlers::component_table_handler::component_table_handler; @@ -20,10 +20,22 @@ pub fn component_routes(state: Arc) -> Router { .route("/admin/component", get(component_table_handler)) .route("/admin/create-component", get(create_component_handler)) .route("/admin/store-component", post(store_component_handler)) - .route("/admin/edit-component/:component_id", get(edit_component_handler)) - .route("/admin/update-component/:component_id", post(update_component_handler)) - .route("/admin/show-component/:component_id", get(show_component_handler)) - .route("/admin/delete-component/:component_id", post(delete_component_handler)) + .route( + "/admin/edit-component/:component_id", + get(edit_component_handler), + ) + .route( + "/admin/update-component/:component_id", + post(update_component_handler), + ) + .route( + "/admin/show-component/:component_id", + get(show_component_handler), + ) + .route( + "/admin/delete-component/:component_id", + post(delete_component_handler), + ) .route_layer(middleware::from_fn_with_state( state.clone(), require_authentication, diff --git a/src/api/component/handlers/component_table_handler.rs b/src/api/component/handlers/component_table_handler.rs index a10da2e9..57cb5ff9 100644 --- a/src/api/component/handlers/component_table_handler.rs +++ b/src/api/component/handlers/component_table_handler.rs @@ -24,20 +24,25 @@ pub async fn component_table_handler( None => AdminUserModel::default(), }; let current_page = query_param.page.unwrap_or(1); - let component_pagination = state.component_service.paginate(&state.db, current_page).await?; + let component_pagination = state + .component_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 = ComponentViewModel { logged_in_user, component_pagination, - success_message + success_message, }; let handlebars = &state.handlebars; let html = handlebars .render("component/component-table", &view_model) - .expect("there is an issue with handlebar rendering component/component-table.hbs template"); + .expect( + "there is an issue with handlebar rendering component/component-table.hbs template", + ); Ok(Html(html)) } diff --git a/src/api/component/handlers/create_component_handler.rs b/src/api/component/handlers/create_component_handler.rs index 3533a155..a4f1f46e 100644 --- a/src/api/component/handlers/create_component_handler.rs +++ b/src/api/component/handlers/create_component_handler.rs @@ -1,15 +1,14 @@ use std::sync::Arc; +use crate::models::admin_user_model::AdminUserModel; use crate::{ - avored_state::AvoRedState, error::Result, - providers::avored_session_provider::AvoRedSession, + avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession, }; use axum::{ extract::State, response::{Html, IntoResponse}, }; use serde::Serialize; -use crate::models::admin_user_model::AdminUserModel; pub async fn create_component_handler( mut session: AvoRedSession, @@ -30,12 +29,18 @@ pub async fn create_component_handler( session.remove("validation_error_name"); session.remove("validation_error_identifier"); - let view_model = CreateComponentViewModel { logged_in_user, validation_name_message, validation_identifier_message }; + let view_model = CreateComponentViewModel { + logged_in_user, + validation_name_message, + validation_identifier_message, + }; let handlebars = &state.handlebars; let html = handlebars .render("component/create-component", &view_model) - .expect("there is an issue with handlebar rendering component/create-component.hbs template"); + .expect( + "there is an issue with handlebar rendering component/create-component.hbs template", + ); Ok(Html(html)) } @@ -44,5 +49,5 @@ pub async fn create_component_handler( pub struct CreateComponentViewModel { pub logged_in_user: AdminUserModel, pub validation_name_message: String, - pub validation_identifier_message: String + pub validation_identifier_message: String, } diff --git a/src/api/component/handlers/delete_component_handler.rs b/src/api/component/handlers/delete_component_handler.rs index 02b26171..0701c8d1 100644 --- a/src/api/component/handlers/delete_component_handler.rs +++ b/src/api/component/handlers/delete_component_handler.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::providers::avored_view_provider::translate; use crate::{ avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession, }; @@ -7,7 +8,6 @@ use axum::{ extract::{Path, State}, response::{IntoResponse, Redirect}, }; -use crate::providers::avored_view_provider::translate; pub async fn delete_component_handler( mut session: AvoRedSession, @@ -15,7 +15,10 @@ pub async fn delete_component_handler( state: State>, ) -> Result { println!("->> {:<12} - delete_component_handler", "HANDLER"); - state.component_service.delete_component(&state.db, component_id).await?; + state + .component_service + .delete_component(&state.db, component_id) + .await?; session .insert("success_message", translate("success_deleted_component")) diff --git a/src/api/component/handlers/edit_component_handler.rs b/src/api/component/handlers/edit_component_handler.rs index a8262935..00fe91fb 100644 --- a/src/api/component/handlers/edit_component_handler.rs +++ b/src/api/component/handlers/edit_component_handler.rs @@ -1,17 +1,15 @@ use std::sync::Arc; +use crate::models::admin_user_model::AdminUserModel; +use crate::models::component_model::ComponentModel; use crate::{ - avored_state::AvoRedState, - error::Result, - providers::avored_session_provider::AvoRedSession, + avored_state::AvoRedState, error::Result, providers::avored_session_provider::AvoRedSession, }; use axum::{ extract::{Path, State}, response::{Html, IntoResponse}, }; use serde::Serialize; -use crate::models::admin_user_model::AdminUserModel; -use crate::models::component_model::ComponentModel; pub async fn edit_component_handler( session: AvoRedSession, @@ -24,12 +22,15 @@ pub async fn edit_component_handler( None => AdminUserModel::default(), }; - let component_model = state.component_service.find_by_id(&state.db, component_id).await?; - + let component_model = state + .component_service + .find_by_id(&state.db, component_id) + .await?; + let mut view_model = EditComponentViewModel::default(); view_model.logged_in_user = logged_in_user; view_model.component_model = component_model; - + let handlebars = &state.handlebars; let html = handlebars .render("component/edit-component", &view_model) diff --git a/src/api/component/handlers/mod.rs b/src/api/component/handlers/mod.rs index b93e147d..16941438 100644 --- a/src/api/component/handlers/mod.rs +++ b/src/api/component/handlers/mod.rs @@ -1,7 +1,7 @@ pub mod component_table_handler; pub mod create_component_handler; -pub mod store_component_handler; +pub mod delete_component_handler; pub mod edit_component_handler; -pub mod update_component_handler; pub mod show_component_handler; -pub mod delete_component_handler; \ No newline at end of file +pub mod store_component_handler; +pub mod update_component_handler; diff --git a/src/api/component/handlers/show_component_handler.rs b/src/api/component/handlers/show_component_handler.rs index fe93005c..2f265387 100644 --- a/src/api/component/handlers/show_component_handler.rs +++ b/src/api/component/handlers/show_component_handler.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::models::component_model::ComponentModel; use crate::{ avored_state::AvoRedState, error::Result, models::admin_user_model::AdminUserModel, providers::avored_session_provider::AvoRedSession, @@ -9,7 +10,6 @@ use axum::{ response::{Html, IntoResponse}, }; use serde::Serialize; -use crate::models::component_model::ComponentModel; pub async fn show_component_handler( session: AvoRedSession, diff --git a/src/api/component/handlers/store_component_handler.rs b/src/api/component/handlers/store_component_handler.rs index 6e9c7092..6bdee6ef 100644 --- a/src/api/component/handlers/store_component_handler.rs +++ b/src/api/component/handlers/store_component_handler.rs @@ -1,9 +1,11 @@ use std::sync::Arc; +use crate::api::component::requests::store_component_request::StoreComponentRequest; +use crate::models::component_model::CreatableComponent; +use crate::models::field_model::CreatableFieldModel; +use crate::providers::avored_view_provider::translate; use crate::{ - avored_state::AvoRedState, - error::Result, - models::admin_user_model::AdminUserModel, + avored_state::AvoRedState, error::Result, models::admin_user_model::AdminUserModel, providers::avored_session_provider::AvoRedSession, }; use avored_better_query::AvoRedForm; @@ -12,10 +14,6 @@ use axum::{ response::{IntoResponse, Redirect}, }; use validator::HasLen; -use crate::api::component::requests::store_component_request::StoreComponentRequest; -use crate::models::component_model::CreatableComponent; -use crate::models::field_model::CreatableFieldModel; -use crate::providers::avored_view_provider::translate; pub async fn store_component_handler( state: State>, @@ -75,15 +73,13 @@ pub async fn store_component_handler( &state.db, created_component.clone(), created_field, - logged_in_user.email.clone() + logged_in_user.email.clone(), ) .await?; println!("ATTACHED: {:?}", created_field); - } - session .insert("success_message", translate("success_created_component")) .expect("Could not store the success message into session."); diff --git a/src/api/component/handlers/update_component_handler.rs b/src/api/component/handlers/update_component_handler.rs index b6525d0b..b3f48272 100644 --- a/src/api/component/handlers/update_component_handler.rs +++ b/src/api/component/handlers/update_component_handler.rs @@ -1,10 +1,10 @@ use std::sync::Arc; +use crate::models::component_model::UpdatableComponentModel; +use crate::providers::avored_view_provider::translate; use crate::{ api::component::requests::update_component_request::UpdateComponentRequest, - avored_state::AvoRedState, - error::Result, - models::admin_user_model::AdminUserModel, + avored_state::AvoRedState, error::Result, models::admin_user_model::AdminUserModel, providers::avored_session_provider::AvoRedSession, }; use avored_better_query::AvoRedForm; @@ -13,8 +13,6 @@ use axum::{ response::{IntoResponse, Redirect}, }; use validator::HasLen; -use crate::models::component_model::UpdatableComponentModel; -use crate::providers::avored_view_provider::translate; pub async fn update_component_handler( mut session: AvoRedSession, @@ -39,7 +37,7 @@ pub async fn update_component_handler( id: component_id, name: payload.name, identifier: payload.identifier, - logged_in_username: logged_in_user.email + logged_in_username: logged_in_user.email, }; let _role_model = state .component_service diff --git a/src/api/component/requests/mod.rs b/src/api/component/requests/mod.rs index 02d49a5c..0d48b187 100644 --- a/src/api/component/requests/mod.rs +++ b/src/api/component/requests/mod.rs @@ -1,3 +1,3 @@ pub mod component_table_query; pub mod store_component_request; -pub mod update_component_request; \ No newline at end of file +pub mod update_component_request; diff --git a/src/api/component/requests/store_component_request.rs b/src/api/component/requests/store_component_request.rs index 03d7eede..a570444e 100644 --- a/src/api/component/requests/store_component_request.rs +++ b/src/api/component/requests/store_component_request.rs @@ -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; @@ -12,7 +12,7 @@ pub struct StoreComponentRequest { #[validate(length(min = 1, message = "The identifier is a required field."))] pub identifier: String, - pub fields: Vec + pub fields: Vec, } #[derive(Deserialize, Debug, Clone, Default)] diff --git a/src/api/component/requests/update_component_request.rs b/src/api/component/requests/update_component_request.rs index 9a139ca1..b97d0e6b 100644 --- a/src/api/component/requests/update_component_request.rs +++ b/src/api/component/requests/update_component_request.rs @@ -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; @@ -13,8 +13,6 @@ pub struct UpdateComponentRequest { pub identifier: String, } - - impl UpdateComponentRequest { pub fn validate_errors(&self, mut session: AvoRedSession) -> Result { let validation_error_list = match self.validate() { diff --git a/src/api/mod.rs b/src/api/mod.rs index 6e84fef9..a0535fc4 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,4 +1,4 @@ pub mod admin_user; -pub mod setup; pub mod component; -pub mod page; \ No newline at end of file +pub mod page; +pub mod setup; diff --git a/src/api/page/handlers/mod.rs b/src/api/page/handlers/mod.rs index 0e527903..b08ee628 100644 --- a/src/api/page/handlers/mod.rs +++ b/src/api/page/handlers/mod.rs @@ -1 +1 @@ -pub mod page_table_handler; \ No newline at end of file +pub mod page_table_handler; diff --git a/src/api/page/handlers/page_table_handler.rs b/src/api/page/handlers/page_table_handler.rs index cac3b124..2bc10888 100644 --- a/src/api/page/handlers/page_table_handler.rs +++ b/src/api/page/handlers/page_table_handler.rs @@ -31,7 +31,7 @@ pub async fn page_table_handler( let view_model = PageViewModel { logged_in_user, page_pagination, - success_message + success_message, }; let handlebars = &state.handlebars; diff --git a/src/api/page/mod.rs b/src/api/page/mod.rs index 1f8859de..5e77eda0 100644 --- a/src/api/page/mod.rs +++ b/src/api/page/mod.rs @@ -1,3 +1,3 @@ -pub mod page_routes; pub mod handlers; -pub mod requests; \ No newline at end of file +pub mod page_routes; +pub mod requests; diff --git a/src/api/page/page_routes.rs b/src/api/page/page_routes.rs index cd2d0221..13597d14 100644 --- a/src/api/page/page_routes.rs +++ b/src/api/page/page_routes.rs @@ -1,16 +1,15 @@ -use std::sync::Arc; -use axum::Router; -use axum::routing::get; use crate::api::page::handlers::page_table_handler::page_table_handler; use crate::avored_state::AvoRedState; +use axum::routing::get; +use axum::Router; +use std::sync::Arc; pub fn page_routes(state: Arc) -> Router { Router::new() .route("/admin/page", get(page_table_handler)) - // .route_layer(middleware::from_fn_with_state( // state.clone(), // require_authentication, // )) .with_state(state) -} \ No newline at end of file +} diff --git a/src/api/page/requests/mod.rs b/src/api/page/requests/mod.rs index feba28b0..7d8c4f55 100644 --- a/src/api/page/requests/mod.rs +++ b/src/api/page/requests/mod.rs @@ -1 +1 @@ -pub mod page_table_query; \ No newline at end of file +pub mod page_table_query; diff --git a/src/api/setup/handlers/mod.rs b/src/api/setup/handlers/mod.rs index 57808a7a..54811114 100644 --- a/src/api/setup/handlers/mod.rs +++ b/src/api/setup/handlers/mod.rs @@ -1,2 +1,2 @@ -pub mod setup_avored_handler; pub mod post_setup_avored_handler; +pub mod setup_avored_handler; diff --git a/src/api/setup/mod.rs b/src/api/setup/mod.rs index 32f48e63..e914ba16 100644 --- a/src/api/setup/mod.rs +++ b/src/api/setup/mod.rs @@ -1,3 +1,3 @@ -pub mod setup_routes; pub mod handlers; pub mod requests; +pub mod setup_routes; diff --git a/src/api/setup/setup_routes.rs b/src/api/setup/setup_routes.rs index faebd54a..24799ebf 100644 --- a/src/api/setup/setup_routes.rs +++ b/src/api/setup/setup_routes.rs @@ -1,10 +1,16 @@ use std::sync::Arc; -use axum::{routing::{get, post}, Router}; +use axum::{ + routing::{get, post}, + Router, +}; use crate::avored_state::AvoRedState; -use super::handlers::{setup_avored_handler::setup_avored_handler, post_setup_avored_handler::post_setup_avored_handler}; +use super::handlers::{ + post_setup_avored_handler::post_setup_avored_handler, + setup_avored_handler::setup_avored_handler, +}; pub fn setup_routes(state: Arc) -> Router { Router::new() diff --git a/src/avored_state.rs b/src/avored_state.rs index 4f057f80..58c4b776 100644 --- a/src/avored_state.rs +++ b/src/avored_state.rs @@ -4,15 +4,15 @@ use crate::providers::avored_database_provider::{AvoRedDatabaseProvider, DB}; use crate::providers::avored_view_provider::AvoRedViewProvider; use crate::repositories::admin_user_repository::AdminUserRepository; use crate::repositories::component_repository::ComponentRepository; +use crate::repositories::field_repository::FieldRepository; +use crate::repositories::page_repository::PageRepository; use crate::repositories::role_repository::RoleRepository; use crate::services::admin_user_service::AdminUserService; use crate::services::component_service::ComponentService; -use crate::services::role_service::RoleService; -use handlebars::Handlebars; -use crate::repositories::field_repository::FieldRepository; -use crate::repositories::page_repository::PageRepository; use crate::services::field_service::FieldService; use crate::services::page_service::PageService; +use crate::services::role_service::RoleService; +use handlebars::Handlebars; pub struct AvoRedState { pub handlebars: Handlebars<'static>, @@ -55,7 +55,7 @@ impl AvoRedState { role_service, component_service, field_service, - page_service + page_service, }) } } diff --git a/src/main.rs b/src/main.rs index 31adcab5..fa06885c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use tracing_subscriber::{ filter, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer, }; +use crate::api::page::page_routes::page_routes; use crate::{ api::{ admin_user::admin_user_routes::admin_user_routes, @@ -21,7 +22,6 @@ use crate::{ error::Result, providers::{avored_config_provider::config, avored_session_provider::SessionLayer}, }; -use crate::api::page::page_routes::page_routes; const PER_PAGE: i64 = 10; diff --git a/src/models/admin_user_model.rs b/src/models/admin_user_model.rs index 93b3eaed..7b6f10af 100644 --- a/src/models/admin_user_model.rs +++ b/src/models/admin_user_model.rs @@ -174,5 +174,5 @@ pub struct UpdatableAdminUserModel { #[derive(Serialize, Debug, Deserialize, Clone, Default)] pub struct AdminUserPagination { pub data: Vec, - pub pagination: Pagination + pub pagination: Pagination, } diff --git a/src/models/component_model.rs b/src/models/component_model.rs index 270a4794..0b4b389e 100644 --- a/src/models/component_model.rs +++ b/src/models/component_model.rs @@ -1,7 +1,7 @@ use crate::error::{Error, Result}; +use crate::models::field_model::FieldModel; use serde::{Deserialize, Serialize}; use surrealdb::sql::{Datetime, Object, Value}; -use crate::models::field_model::FieldModel; use super::Pagination; @@ -14,7 +14,7 @@ pub struct ComponentModel { pub updated_at: Datetime, pub created_by: String, pub updated_by: String, - pub fields: Vec + pub fields: Vec, } impl TryFrom for ComponentModel { @@ -130,7 +130,7 @@ impl TryFrom for ComponentModel { updated_at, created_by, updated_by, - fields: fields + fields: fields, }) } } @@ -139,7 +139,7 @@ impl TryFrom for ComponentModel { pub struct CreatableComponent { pub name: String, pub identifier: String, - pub logged_in_username: String + pub logged_in_username: String, } #[derive(Serialize, Debug, Deserialize, Clone)] diff --git a/src/models/mod.rs b/src/models/mod.rs index ba5b203f..4b1e7d59 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -3,10 +3,10 @@ use serde::{Deserialize, Serialize}; use surrealdb::sql::{Object, Value}; pub mod admin_user_model; -pub mod role_model; pub mod component_model; pub mod field_model; pub mod page_model; +pub mod role_model; #[derive(Serialize, Debug, Deserialize, Clone, Default)] pub struct Pagination { diff --git a/src/models/page_model.rs b/src/models/page_model.rs index aaaf1c83..944b5204 100644 --- a/src/models/page_model.rs +++ b/src/models/page_model.rs @@ -19,76 +19,61 @@ impl TryFrom for PageModel { type Error = Error; fn try_from(val: Object) -> Result { let id = match val.get("id") { - Some(val) => { - match val.clone() { - Value::Thing(v) => { - let id = v.id; - id.to_string() - } - _ => String::from(""), + Some(val) => match val.clone() { + Value::Thing(v) => { + let id = v.id; + id.to_string() } - } + _ => String::from(""), + }, None => String::from(""), }; let name = match val.get("name") { - Some(val) => { - match val.clone() { - Value::Strand(v) => v.as_string(), - _ => String::from(""), - } - } + Some(val) => match val.clone() { + Value::Strand(v) => v.as_string(), + _ => String::from(""), + }, None => String::from(""), }; let identifier = match val.get("identifier") { - Some(val) => { - match val.clone() { - Value::Strand(v) => v.as_string(), - _ => String::from(""), - } - } + Some(val) => match val.clone() { + Value::Strand(v) => v.as_string(), + _ => String::from(""), + }, None => String::from(""), }; let created_at = match val.get("created_at") { - Some(val) => { - match val.clone() { - Value::Datetime(v) => v, - _ => Datetime::default(), - } - } + Some(val) => match val.clone() { + Value::Datetime(v) => v, + _ => Datetime::default(), + }, None => Datetime::default(), }; let updated_at = match val.get("updated_at") { - Some(val) => { - match val.clone() { - Value::Datetime(v) => v, - _ => Datetime::default(), - } - } + Some(val) => match val.clone() { + Value::Datetime(v) => v, + _ => Datetime::default(), + }, None => Datetime::default(), }; let created_by = match val.get("created_by") { - Some(val) => { - match val.clone() { - Value::Strand(v) => v.as_string(), - _ => String::from(""), - } - } + Some(val) => match val.clone() { + Value::Strand(v) => v.as_string(), + _ => String::from(""), + }, None => String::from(""), }; let updated_by = match val.get("updated_by") { - Some(val) => { - match val.clone() { - Value::Strand(v) => v.as_string(), - _ => String::from(""), - } - } + Some(val) => match val.clone() { + Value::Strand(v) => v.as_string(), + _ => String::from(""), + }, None => String::from(""), }; - Ok(PageModel { id, name, @@ -101,7 +86,6 @@ impl TryFrom for PageModel { } } - #[derive(Serialize, Debug, Deserialize, Clone, Default)] pub struct PagePagination { pub data: Vec, diff --git a/src/models/role_model.rs b/src/models/role_model.rs index 0db1908c..556f98b4 100644 --- a/src/models/role_model.rs +++ b/src/models/role_model.rs @@ -132,7 +132,7 @@ pub struct CreatableRole { pub name: String, pub identifier: String, pub logged_in_username: String, - pub permissions: Vec + pub permissions: Vec, } #[derive(Serialize, Debug, Deserialize, Clone)] @@ -141,7 +141,7 @@ pub struct UpdatableRoleModel { pub name: String, pub identifier: String, pub logged_in_username: String, - pub permissions: Vec + pub permissions: Vec, } #[derive(Serialize, Debug, Deserialize, Clone, Default)] diff --git a/src/providers/avored_config_provider.rs b/src/providers/avored_config_provider.rs index c0f91814..c4f17a42 100644 --- a/src/providers/avored_config_provider.rs +++ b/src/providers/avored_config_provider.rs @@ -1,4 +1,4 @@ -use std::{sync::OnceLock, env}; +use std::{env, sync::OnceLock}; use dotenvy::dotenv; @@ -8,10 +8,9 @@ use crate::error::{Error, Result}; pub struct AvoRedConfigProvider { pub database_namespace: String, pub database_name: String, - pub session_secret_key: String + pub session_secret_key: String, } - pub fn config() -> &'static AvoRedConfigProvider { static INSTANCE: OnceLock = OnceLock::new(); @@ -27,7 +26,7 @@ impl AvoRedConfigProvider { Ok(AvoRedConfigProvider { database_namespace: get_env("AVORED_DATABASE_NAMESPACE")?, database_name: get_env("AVORED_DATABASE_NAME")?, - session_secret_key: get_env("AVORED_SESSION_SECRET_KEY")? + session_secret_key: get_env("AVORED_SESSION_SECRET_KEY")?, }) } } diff --git a/src/providers/avored_database_provider.rs b/src/providers/avored_database_provider.rs index 93068f3d..3edd6ed4 100644 --- a/src/providers/avored_database_provider.rs +++ b/src/providers/avored_database_provider.rs @@ -1,7 +1,7 @@ +use crate::error::Result; use crate::providers::avored_config_provider::AvoRedConfigProvider; -use surrealdb::kvs::Datastore; use surrealdb::dbs::Session; -use crate::error::Result; +use surrealdb::kvs::Datastore; pub type DB = (Datastore, Session); pub struct AvoRedDatabaseProvider { diff --git a/src/providers/avored_session_provider.rs b/src/providers/avored_session_provider.rs index 9f9b15b0..d6d0d91d 100644 --- a/src/providers/avored_session_provider.rs +++ b/src/providers/avored_session_provider.rs @@ -171,7 +171,6 @@ impl SessionLayer { session .and_then(async_session::Session::validate) .unwrap_or_default() - } fn build_cookie(&self, cookie_value: String) -> Cookie<'static> { @@ -306,7 +305,7 @@ where let mut response = inner.call(request).await?; let session: async_session::Session = session; - let session_is_destroyed = session.is_destroyed(); + let session_is_destroyed = session.is_destroyed(); if session_is_destroyed { if let Err(e) = session_layer.store.destroy_session(session).await { @@ -375,7 +374,7 @@ where Extension::from_request_parts(parts, state) .await .expect("Session extension missing. Is the session layer installed?"); - let session = session_handle.clone(); + let session = session_handle.clone(); Ok(Self { session }) } diff --git a/src/providers/avored_view_provider.rs b/src/providers/avored_view_provider.rs index b04b8eb8..4fbe977b 100644 --- a/src/providers/avored_view_provider.rs +++ b/src/providers/avored_view_provider.rs @@ -108,11 +108,10 @@ fn is_vector_contains( let mut find_key_result = ""; if vector_value.into_iter().any(|i| { - - // Try to fix this trim issue + // Try to fix this trim issue let index = i.to_string(); let trim_str = index.trim_matches('"'); - + trim_str.eq(&find_key_value) }) { // this value wont be used anyhow yet. diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 0a9b8197..f0caa93a 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -1,4 +1,4 @@ -pub mod avored_view_provider; pub mod avored_config_provider; -pub mod avored_session_provider; pub mod avored_database_provider; +pub mod avored_session_provider; +pub mod avored_view_provider; diff --git a/src/repositories/component_repository.rs b/src/repositories/component_repository.rs index 7b1b0d2e..707f2966 100644 --- a/src/repositories/component_repository.rs +++ b/src/repositories/component_repository.rs @@ -2,12 +2,12 @@ use std::collections::BTreeMap; use crate::error::{Error, Result}; use crate::models::component_model::{ComponentModel, CreatableComponent, UpdatableComponentModel}; +use crate::models::field_model::FieldModel; use crate::models::ModelCount; use crate::PER_PAGE; use surrealdb::dbs::Session; use surrealdb::kvs::Datastore; use surrealdb::sql::{Datetime, Value}; -use crate::models::field_model::FieldModel; use super::into_iter_objects; @@ -89,7 +89,8 @@ impl ComponentRepository { database_session: &Session, component_id: String, ) -> Result { - let sql = "SELECT *, ->component_field<-components.* as fields FROM type::thing($table, $id);"; + let sql = + "SELECT *, ->component_field<-components.* as fields FROM type::thing($table, $id);"; let vars: BTreeMap = [ ("id".into(), component_id.into()), ("table".into(), "components".into()), @@ -188,7 +189,7 @@ impl ComponentRepository { Ok(obj) => obj.try_into(), Err(_) => Ok(ModelCount::default()), }; - + total_count } @@ -198,22 +199,26 @@ impl ComponentRepository { database_session: &Session, component_model: ComponentModel, field_model: FieldModel, - logged_in_username: String + logged_in_username: String, ) -> Result { - let sql = format!("RELATE {}:{}->{}->{}:{} CONTENT $attached_data;", "components", component_model.id, "component_field", "fields", field_model.id); + let sql = format!( + "RELATE {}:{}->{}->{}:{} CONTENT $attached_data;", + "components", component_model.id, "component_field", "fields", field_model.id + ); let attached_data: BTreeMap = [ ("created_by".into(), logged_in_username.clone().into()), ("updated_by".into(), logged_in_username.into()), ("created_at".into(), Datetime::default().into()), ("updated_at".into(), Datetime::default().into()), - ].into(); + ] + .into(); - let vars: BTreeMap = [ - ("attached_data".into(), attached_data.into()), - ].into(); + let vars: BTreeMap = [("attached_data".into(), attached_data.into())].into(); - let responses = datastore.execute(sql.as_str(), database_session, Some(vars)).await?; + let responses = datastore + .execute(sql.as_str(), database_session, Some(vars)) + .await?; let response = responses.into_iter().next().map(|rp| rp.result).transpose(); if response.is_ok() { @@ -222,5 +227,4 @@ impl ComponentRepository { Ok(true) } - } diff --git a/src/repositories/field_repository.rs b/src/repositories/field_repository.rs index c0c8ff48..188eb86d 100644 --- a/src/repositories/field_repository.rs +++ b/src/repositories/field_repository.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use crate::error::{Error, Result}; -use crate::models::field_model::{FieldModel, CreatableFieldModel}; +use crate::models::field_model::{CreatableFieldModel, FieldModel}; use surrealdb::dbs::Session; use surrealdb::kvs::Datastore; use surrealdb::sql::{Datetime, Value}; @@ -47,8 +47,6 @@ impl FieldRepository { ) -> Result { let sql = "CREATE fields CONTENT $data"; - - let data: BTreeMap = [ ("name".into(), createable_field_model.name.into()), ( diff --git a/src/repositories/mod.rs b/src/repositories/mod.rs index c3cfcc29..5ae80d40 100644 --- a/src/repositories/mod.rs +++ b/src/repositories/mod.rs @@ -3,10 +3,10 @@ use surrealdb::dbs::Response; use surrealdb::sql::{Object, Value}; pub mod admin_user_repository; -pub mod role_repository; pub mod component_repository; pub mod field_repository; pub mod page_repository; +pub mod role_repository; fn into_iter_objects(responses: Vec) -> Result>> { let response = responses diff --git a/src/repositories/role_repository.rs b/src/repositories/role_repository.rs index 3f9b6f9a..cd7a9570 100644 --- a/src/repositories/role_repository.rs +++ b/src/repositories/role_repository.rs @@ -52,7 +52,10 @@ impl RoleRepository { let data: BTreeMap = [ ("name".into(), createable_role_model.name.into()), ("identifier".into(), createable_role_model.identifier.into()), - ("permissions".into(), createable_role_model.permissions.into()), + ( + "permissions".into(), + createable_role_model.permissions.into(), + ), ( "created_by".into(), createable_role_model.logged_in_username.clone().into(), @@ -126,7 +129,10 @@ impl RoleRepository { let vars = BTreeMap::from([ ("name".into(), updatable_admin_user.name.into()), ("identifier".into(), updatable_admin_user.identifier.into()), - ("permissions".into(), updatable_admin_user.permissions.into()), + ( + "permissions".into(), + updatable_admin_user.permissions.into(), + ), ( "logged_in_user_name".into(), updatable_admin_user.logged_in_username.into(), diff --git a/src/services/component_service.rs b/src/services/component_service.rs index 414db756..3fb8e916 100644 --- a/src/services/component_service.rs +++ b/src/services/component_service.rs @@ -1,14 +1,16 @@ +use crate::models::field_model::FieldModel; use crate::{ error::Result, models::{ - component_model::{CreatableComponent, ComponentModel, ComponentPagination, UpdatableComponentModel}, + component_model::{ + ComponentModel, ComponentPagination, CreatableComponent, UpdatableComponentModel, + }, Pagination, }, providers::avored_database_provider::DB, repositories::component_repository::ComponentRepository, PER_PAGE, }; -use crate::models::field_model::FieldModel; pub struct ComponentService { component_repository: ComponentRepository, @@ -16,11 +18,12 @@ pub struct ComponentService { impl ComponentService { pub fn new(component_repository: ComponentRepository) -> Result { - Ok(ComponentService { component_repository }) + Ok(ComponentService { + component_repository, + }) } } impl ComponentService { - pub async fn paginate( &self, (datastore, database_session): &DB, @@ -111,10 +114,16 @@ impl ComponentService { (datastore, database_session): &DB, component_model: ComponentModel, field_model: FieldModel, - logged_in_username: String + logged_in_username: String, ) -> Result { self.component_repository - .attach_component_with_field(datastore, database_session, component_model, field_model, logged_in_username) + .attach_component_with_field( + datastore, + database_session, + component_model, + field_model, + logged_in_username, + ) .await } } diff --git a/src/services/field_service.rs b/src/services/field_service.rs index ede4e5dc..c9c4adf6 100644 --- a/src/services/field_service.rs +++ b/src/services/field_service.rs @@ -1,8 +1,6 @@ use crate::{ error::Result, - models::{ - field_model::{CreatableFieldModel, FieldModel} - }, + models::field_model::{CreatableFieldModel, FieldModel}, providers::avored_database_provider::DB, repositories::field_repository::FieldRepository, }; @@ -17,7 +15,6 @@ impl FieldService { } } impl FieldService { - // pub async fn paginate( // &self, // (datastore, database_session): &DB, @@ -68,7 +65,6 @@ impl FieldService { (datastore, database_session): &DB, creatable_field_model: CreatableFieldModel, ) -> Result { - // Think of how we going to do a DB transaction // create field // create field diff --git a/src/services/mod.rs b/src/services/mod.rs index 4ec32cc1..9c3e9d14 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -1,5 +1,5 @@ pub mod admin_user_service; -pub mod role_service; pub mod component_service; pub mod field_service; -pub mod page_service; \ No newline at end of file +pub mod page_service; +pub mod role_service; diff --git a/src/services/page_service.rs b/src/services/page_service.rs index 439854b4..df59e45e 100644 --- a/src/services/page_service.rs +++ b/src/services/page_service.rs @@ -1,9 +1,6 @@ use crate::{ error::Result, - models::{ - page_model::PagePagination, - Pagination, - }, + models::{page_model::PagePagination, Pagination}, providers::avored_database_provider::DB, repositories::page_repository::PageRepository, PER_PAGE, @@ -53,7 +50,6 @@ impl PageService { previous_page_number: (current_page - 1), }; - let pages = self .page_repository .paginate(datastore, database_session, start) @@ -66,5 +62,4 @@ impl PageService { pagination, }) } - } diff --git a/src/services/role_service.rs b/src/services/role_service.rs index afbbd012..e75fad67 100644 --- a/src/services/role_service.rs +++ b/src/services/role_service.rs @@ -92,7 +92,6 @@ impl RoleService { previous_page_number: (current_page - 1), }; - let roles = self .role_repository .paginate(datastore, database_session, start)