feat(dimentorin): complete articles module - HTTP layer, routes, categories fix, seed
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
use super::handlers::{
|
||||
get_article_by_id, get_article_by_slug, get_article_categories,
|
||||
get_articles_list, post_create_article,
|
||||
};
|
||||
use crate::articles::application::ArticleServiceImpl;
|
||||
use crate::articles::domain::ArticleService;
|
||||
use crate::articles::infrastructure::persistence::PostgresArticleRepository;
|
||||
use axum::{Extension, Router, routing::{get, post}};
|
||||
use imphnen_libs::AppState;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn build_service(db: DatabaseConnection) -> Arc<dyn ArticleService> {
|
||||
let repo = Arc::new(PostgresArticleRepository::new(db));
|
||||
Arc::new(ArticleServiceImpl::new(repo))
|
||||
}
|
||||
|
||||
pub fn articles_public_routes(db: DatabaseConnection) -> Router {
|
||||
let service = build_service(db);
|
||||
Router::new()
|
||||
.route("/articles", get(get_articles_list))
|
||||
.route("/articles/categories", get(get_article_categories))
|
||||
.route("/articles/slug/{slug}", get(get_article_by_slug))
|
||||
.route("/articles/{id}", get(get_article_by_id))
|
||||
.layer(Extension(service))
|
||||
}
|
||||
|
||||
pub fn articles_protected_routes(
|
||||
db: DatabaseConnection,
|
||||
state: Arc<AppState>,
|
||||
) -> Router {
|
||||
let service = build_service(db);
|
||||
Router::new()
|
||||
.route("/articles/create", post(post_create_article))
|
||||
.layer(Extension(service))
|
||||
.layer(Extension((*state).clone()))
|
||||
}
|
||||
Reference in New Issue
Block a user