Skip to content

Commit

Permalink
move endpoint to route
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia committed Sep 14, 2024
1 parent 76cfa0b commit 6aadba3
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 17 deletions.
18 changes: 11 additions & 7 deletions nghe-backend/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ use crate::filesystem::Filesystem;

mod auth;
mod common;
pub mod migration;
pub mod music_folder;
pub mod permission;
pub mod route;
pub mod state;
pub mod user;

pub async fn build(config: Config) -> Router {
let filesystem = Filesystem::new(&config.filesystem.tls, &config.filesystem.s3).await;

Router::new()
.merge(music_folder::router(filesystem))
.merge(permission::router())
.merge(user::router())
.merge(route::music_folder::router(filesystem))
.merge(route::permission::router())
.merge(route::user::router())
.with_state(state::App::new(&config.database))
.layer(TraceLayer::new_for_http().make_span_with(|request: &Request<Body>| {
tracing::info_span!(
"request", method = %request.method(), uri = %request.uri()
)
}))
}

#[cfg(test)]
pub mod test {
pub mod permission {
pub use super::super::route::permission::test::*;
}
}
3 changes: 3 additions & 0 deletions nghe-backend/src/app/route/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod music_folder;
pub mod permission;
pub mod user;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use nghe_api::music_folder::add::{Request, Response};
use nghe_proc_macro::handler;
use uuid::Uuid;

use crate::app::permission;
use crate::app::route::permission;
use crate::app::state::Database;
use crate::error::Error;
use crate::filesystem::{self, Filesystem, Trait as _};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
use rstest::rstest;

use super::*;
use crate::app::permission::test::{count, reset};
use crate::app::test::permission::{count, reset};
use crate::test::{mock, Mock};

#[rstest]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod add;

#[cfg(test)]
mod test;
pub mod test;

nghe_proc_macro::build_router! {
modules = [add]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use diesel_async::RunQueryDsl;
pub use nghe_api::user::create::{Request, Response};
use nghe_proc_macro::handler;

use crate::app::permission;
use crate::app::route::permission;
use crate::app::state::Database;
use crate::orm::users;
use crate::Error;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub use nghe_api::user::setup::{Request, Response};
use nghe_api::user::Role;
use nghe_proc_macro::handler;

use super::create;
use crate::app::state::Database;
use crate::app::user::create;
use crate::orm::users;
use crate::Error;

Expand Down
3 changes: 2 additions & 1 deletion nghe-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ pub mod config;
mod error;
mod filesystem;
mod media;
pub mod migration;
mod orm;
mod schema;

pub use app::{build, migration};
pub use app::build;
use error::Error;

#[cfg(test)]
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions nghe-backend/src/test/mock_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rstest::fixture;

use super::filesystem::Trait;
use super::{database, filesystem};
use crate::app::route;
use crate::filesystem::Filesystem;
use crate::orm::users;
use crate::{app, config};
Expand Down Expand Up @@ -66,9 +67,9 @@ impl Mock {
role: users::Role,
#[builder(default = true)] allow: bool,
) -> &Self {
app::user::create::handler(
route::user::create::handler(
self.database(),
app::user::create::Request { role: role.into(), allow, ..Faker.fake() },
route::user::create::Request { role: role.into(), allow, ..Faker.fake() },
)
.await
.unwrap();
Expand All @@ -95,10 +96,10 @@ impl Mock {
#[builder(default = true)] allow: bool,
) -> &Self {
let filesystem = self.to_impl(filesystem_type);
app::music_folder::add::handler(
route::music_folder::add::handler(
self.database(),
self.filesystem(),
app::music_folder::add::Request {
route::music_folder::add::Request {
filesystem_type,
allow,
path: filesystem
Expand Down

0 comments on commit 6aadba3

Please sign in to comment.