Skip to content

Commit

Permalink
feat: update route implementation (#16)
Browse files Browse the repository at this point in the history
* chore: enable the support modified

* feat: set routes per feature

* fix: remove ;

* chore: change ip database to localhost
  • Loading branch information
Lzyct authored Sep 24, 2024
1 parent 1ffa0b9 commit 3aac3f1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ POSTGRES_USER=admin
POSTGRES_PASSWORD=password123
POSTGRES_DB=auth_api

DATABASE_URL=postgresql://admin:password123@0.0.0.0:6500/auth_api
DATABASE_URL=postgresql://admin:password123@localhost:6500/auth_api

TOKEN_PREFIX=lazycatlabs

Expand All @@ -25,4 +25,4 @@ MAIL_SECRET_KEY=your_mailjet_secret_key
APP_HOST=localhost
APP_PORT=8000

IS_SUPPORT_MODIFIED=false
IS_SUPPORT_MODIFIED=true
53 changes: 4 additions & 49 deletions src/core/config/routes.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,17 @@
use actix_web::web;

use crate::{
features::{auth::auth_controller, general::general_controller, user::user_controller},
features::{auth::routes::auth_scope, general::routes::general_scope, user::routes::user_scope},
utils::handler::route_not_found,
};

pub fn config_services(cfg: &mut web::ServiceConfig) {
// Configuring routes
cfg.service(
web::scope("/api")
.service(
web::scope("/general")
.service(
web::resource("/send_email")
.route(web::post().to(general_controller::mail_sender_controller)),
)
.service(
web::resource("/health_checker")
.route(web::get().to(general_controller::health_checker_controller)),
),
)
.service(
web::scope("/auth")
.service(
web::resource("/general")
.route(web::post().to(auth_controller::general_token_controller)),
)
.service(
web::resource("/login")
.route(web::post().to(auth_controller::login_contoller)),
)
.service(
web::resource("/logout")
.route(web::post().to(auth_controller::logout_controller)),
)
.service(
web::resource("/session")
.route(web::get().to(auth_controller::login_session_controller)),
)
.service(
web::resource("/password")
.route(web::put().to(auth_controller::update_password_controller)),
),
)
.service(
web::scope("/user")
.service(
web::resource("")
.route(web::post().to(user_controller::register_controller))
.route(web::get().to(user_controller::get_user))
.route(web::put().to(user_controller::update_user_controller))
.route(web::delete().to(user_controller::delete_user_controller)),
)
.service(
web::resource("/all")
.route(web::get().to(user_controller::users_controller)),
),
),
.service(general_scope())
.service(auth_scope())
.service(user_scope()),
)
.default_service(web::route().to(route_not_found));
}
1 change: 1 addition & 0 deletions src/features/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod auth_controller;
pub mod data;
pub mod domain;
pub mod routes;
27 changes: 27 additions & 0 deletions src/features/auth/routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use actix_web::web;

use super::auth_controller;

pub fn auth_scope() -> actix_web::Scope {
web::scope("/auth")
.service(
web::resource("/general")
.route(web::post().to(auth_controller::general_token_controller)),
)
.service(
web::resource("/login")
.route(web::post().to(auth_controller::login_contoller)), // Fixed typo: login_contoller -> login_controller
)
.service(
web::resource("/logout")
.route(web::post().to(auth_controller::logout_controller)),
)
.service(
web::resource("/session")
.route(web::get().to(auth_controller::login_session_controller)),
)
.service(
web::resource("/password")
.route(web::put().to(auth_controller::update_password_controller)),
)
}
1 change: 1 addition & 0 deletions src/features/general/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod domain;
pub mod general_controller;
pub mod routes;
15 changes: 15 additions & 0 deletions src/features/general/routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use actix_web::web;

use super::general_controller;

pub fn general_scope() -> actix_web::Scope {
web::scope("/general")
.service(
web::resource("/send_email")
.route(web::post().to(general_controller::mail_sender_controller)),
)
.service(
web::resource("/health_checker")
.route(web::get().to(general_controller::health_checker_controller)),
)
}
1 change: 1 addition & 0 deletions src/features/user/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod data;
pub mod domain;
pub mod user_controller;
pub mod routes;
18 changes: 18 additions & 0 deletions src/features/user/routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use actix_web::web;

use super::user_controller;

pub fn user_scope() -> actix_web::Scope {
web::scope("/user")
.service(
web::resource("")
.route(web::post().to(user_controller::register_controller))
.route(web::get().to(user_controller::get_user))
.route(web::put().to(user_controller::update_user_controller))
.route(web::delete().to(user_controller::delete_user_controller)),
)
.service(
web::resource("/all")
.route(web::get().to(user_controller::users_controller)),
)
}

0 comments on commit 3aac3f1

Please sign in to comment.