use crate::domain::models::{Article, ArticleVersion, Column, Media, Tag}; use crate::infrastructure::repositories; use common_telemetry::AppError; use sqlx::PgPool; use uuid::Uuid; #[derive(Clone)] pub struct CmsServices { pool: PgPool, } impl CmsServices { pub fn new(pool: PgPool) -> Self { Self { pool } } pub async fn create_column( &self, tenant_id: Uuid, name: String, slug: String, description: Option, parent_id: Option, sort_order: i32, ) -> Result { repositories::column::create_column( &self.pool, tenant_id, name, slug, description, parent_id, sort_order, ) .await } pub async fn list_columns( &self, tenant_id: Uuid, q: repositories::column::ListColumnsQuery, ) -> Result, AppError> { repositories::column::list_columns(&self.pool, tenant_id, q).await } pub async fn get_column(&self, tenant_id: Uuid, id: Uuid) -> Result { repositories::column::get_column(&self.pool, tenant_id, id).await } pub async fn update_column( &self, tenant_id: Uuid, id: Uuid, name: Option, slug: Option, description: Option>, parent_id: Option>, sort_order: Option, ) -> Result { repositories::column::update_column( &self.pool, tenant_id, id, name, slug, description, parent_id, sort_order, ) .await } pub async fn delete_column(&self, tenant_id: Uuid, id: Uuid) -> Result<(), AppError> { repositories::column::delete_column(&self.pool, tenant_id, id).await } pub async fn create_tag( &self, tenant_id: Uuid, kind: String, name: String, slug: String, ) -> Result { repositories::tag::create_tag(&self.pool, tenant_id, kind, name, slug).await } pub async fn list_tags( &self, tenant_id: Uuid, q: repositories::tag::ListTagsQuery, ) -> Result, AppError> { repositories::tag::list_tags(&self.pool, tenant_id, q).await } pub async fn get_tag(&self, tenant_id: Uuid, id: Uuid) -> Result { repositories::tag::get_tag(&self.pool, tenant_id, id).await } pub async fn update_tag( &self, tenant_id: Uuid, id: Uuid, name: Option, slug: Option, ) -> Result { repositories::tag::update_tag(&self.pool, tenant_id, id, name, slug).await } pub async fn delete_tag(&self, tenant_id: Uuid, id: Uuid) -> Result<(), AppError> { repositories::tag::delete_tag(&self.pool, tenant_id, id).await } pub async fn create_media( &self, tenant_id: Uuid, url: String, mime_type: Option, size_bytes: Option, width: Option, height: Option, created_by: Option, ) -> Result { repositories::media::create_media( &self.pool, tenant_id, url, mime_type, size_bytes, width, height, created_by, ) .await } pub async fn list_media( &self, tenant_id: Uuid, q: repositories::media::ListMediaQuery, ) -> Result, AppError> { repositories::media::list_media(&self.pool, tenant_id, q).await } pub async fn get_media(&self, tenant_id: Uuid, id: Uuid) -> Result { repositories::media::get_media(&self.pool, tenant_id, id).await } pub async fn delete_media(&self, tenant_id: Uuid, id: Uuid) -> Result<(), AppError> { repositories::media::delete_media(&self.pool, tenant_id, id).await } pub async fn create_article( &self, tenant_id: Uuid, column_id: Option, title: String, slug: String, summary: Option, content: String, tag_ids: Vec, created_by: Option, ) -> Result { repositories::article::create_article( &self.pool, tenant_id, column_id, title, slug, summary, content, tag_ids, created_by, ) .await } pub async fn get_article( &self, tenant_id: Uuid, id: Uuid, ) -> Result { repositories::article::get_article(&self.pool, tenant_id, id).await } pub async fn list_articles( &self, tenant_id: Uuid, q: repositories::article::ListArticlesQuery, ) -> Result, AppError> { repositories::article::list_articles(&self.pool, tenant_id, q).await } pub async fn update_article( &self, tenant_id: Uuid, id: Uuid, column_id: Option>, title: Option, slug: Option, summary: Option>, content: Option, tag_ids: Option>, updated_by: Option, ) -> Result { repositories::article::update_article( &self.pool, tenant_id, id, column_id, title, slug, summary, content, tag_ids, updated_by, ) .await } pub async fn publish_article( &self, tenant_id: Uuid, id: Uuid, user_id: Option, ) -> Result { repositories::article::publish_article(&self.pool, tenant_id, id, user_id).await } pub async fn rollback_article( &self, tenant_id: Uuid, id: Uuid, to_version: i32, user_id: Option, ) -> Result { repositories::article::rollback_article(&self.pool, tenant_id, id, to_version, user_id) .await } pub async fn list_versions( &self, tenant_id: Uuid, article_id: Uuid, page: u32, page_size: u32, ) -> Result, AppError> { repositories::article::list_versions(&self.pool, tenant_id, article_id, page, page_size) .await } }