feat(dimentorin): complete articles module - HTTP layer, routes, categories fix, seed

This commit is contained in:
asepharyana
2026-08-04 19:16:45 +07:00
parent 7d1078f52a
commit 1d34d29b0b
15 changed files with 363 additions and 7 deletions
@@ -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()))
}