refactor: visibility of services

This commit is contained in:
GW_MC
2026-05-28 13:17:22 +00:00
parent c11d9f5a1f
commit c88af8391d
6 changed files with 30 additions and 12 deletions

View File

@@ -45,7 +45,13 @@ pub trait CacheRepo: Send + Sync + 'static {
} }
pub struct CacheRepoImpl { pub struct CacheRepoImpl {
pub db: DatabaseConnection, db: DatabaseConnection,
}
impl CacheRepoImpl {
pub fn new(db: DatabaseConnection) -> Self {
Self { db }
}
} }
#[async_trait::async_trait] #[async_trait::async_trait]

View File

@@ -53,7 +53,7 @@ impl CacheServiceImpl<super::repo::CacheRepoImpl> {
pub fn new(db: DatabaseConnection) -> Self { pub fn new(db: DatabaseConnection) -> Self {
Self { Self {
db: db.clone(), db: db.clone(),
repo: Arc::new(super::repo::CacheRepoImpl { db }), repo: Arc::new(super::repo::CacheRepoImpl::new(db)),
} }
} }
} }

View File

@@ -2,8 +2,8 @@ use std::sync::Arc;
use crate::{ use crate::{
db::{ db::{
entities::category::{ActiveModel as CategoryActiveModel, Entity as CategoryEntity},
Db, Db,
entities::category::{ActiveModel as CategoryActiveModel, Entity as CategoryEntity},
}, },
services::transaction::category::{ services::transaction::category::{
Category, CategoryServiceError, CategoryServiceResult, CategoryWithParent, Category, CategoryServiceError, CategoryServiceResult, CategoryWithParent,
@@ -22,7 +22,7 @@ pub trait CategoryRepoService: Send + Sync + 'static {
async fn get_category(&self, id: i64) -> Result<Option<CategoryWithParent>>; async fn get_category(&self, id: i64) -> Result<Option<CategoryWithParent>>;
async fn create_category(&self, request: CreateCategoryRequest) -> Result<i64>; async fn create_category(&self, request: CreateCategoryRequest) -> Result<i64>;
async fn create_category_with_tx(&self, request: CreateCategoryRequest, tx: &Db) async fn create_category_with_tx(&self, request: CreateCategoryRequest, tx: &Db)
-> Result<i64>; -> Result<i64>;
async fn update_category(&self, id: i64, request: UpdateCategoryRequest) -> Result<()>; async fn update_category(&self, id: i64, request: UpdateCategoryRequest) -> Result<()>;
async fn update_category_with_tx( async fn update_category_with_tx(
&self, &self,
@@ -35,7 +35,13 @@ pub trait CategoryRepoService: Send + Sync + 'static {
#[derive(Clone)] #[derive(Clone)]
pub struct CategoryRepoServiceImpl { pub struct CategoryRepoServiceImpl {
pub db: DatabaseConnection, db: DatabaseConnection,
}
impl CategoryRepoServiceImpl {
pub fn new(db: DatabaseConnection) -> Self {
Self { db }
}
} }
struct CategorySelfRefLink; struct CategorySelfRefLink;

View File

@@ -6,8 +6,8 @@ use thiserror::Error;
use crate::{ use crate::{
db::{Db, DbServiceError}, db::{Db, DbServiceError},
services::transaction::category::{ services::transaction::category::{
repo::{CategoryRepoService, CategoryRepoServiceImpl},
Category, CategoryWithParent, CreateCategoryRequest, UpdateCategoryRequest, Category, CategoryWithParent, CreateCategoryRequest, UpdateCategoryRequest,
repo::{CategoryRepoService, CategoryRepoServiceImpl},
}, },
}; };
@@ -39,7 +39,7 @@ pub trait CategoryService: Send + Sync + 'static {
async fn get_category(&self, id: i64) -> Result<Option<CategoryWithParent>>; async fn get_category(&self, id: i64) -> Result<Option<CategoryWithParent>>;
async fn create_category(&self, request: CreateCategoryRequest) -> Result<i64>; async fn create_category(&self, request: CreateCategoryRequest) -> Result<i64>;
async fn create_category_with_tx(&self, request: CreateCategoryRequest, tx: &Db) async fn create_category_with_tx(&self, request: CreateCategoryRequest, tx: &Db)
-> Result<i64>; -> Result<i64>;
async fn update_category(&self, id: i64, request: UpdateCategoryRequest) -> Result<()>; async fn update_category(&self, id: i64, request: UpdateCategoryRequest) -> Result<()>;
async fn update_category_with_tx( async fn update_category_with_tx(
&self, &self,
@@ -62,7 +62,7 @@ impl CategoryServiceImpl<CategoryRepoServiceImpl> {
pub fn new(db: DatabaseConnection) -> Self { pub fn new(db: DatabaseConnection) -> Self {
Self { Self {
db: db.clone(), db: db.clone(),
category_repo: Arc::new(CategoryRepoServiceImpl { db }), category_repo: Arc::new(CategoryRepoServiceImpl::new(db)),
} }
} }
} }

View File

@@ -1,5 +1,6 @@
use crate::{ use crate::{
db::{ db::{
Db,
entities::{ entities::{
tag::{ActiveModel as TagActiveModel, Entity as TagEntity}, tag::{ActiveModel as TagActiveModel, Entity as TagEntity},
transaction_tag::{ transaction_tag::{
@@ -7,7 +8,6 @@ use crate::{
Entity as TransactionTagEntity, Entity as TransactionTagEntity,
}, },
}, },
Db,
}, },
services::transaction::tag::{ services::transaction::tag::{
CreateTagRequest, Tag, TagServiceError, TagServiceResult, UpdateTagRequest, CreateTagRequest, Tag, TagServiceError, TagServiceResult, UpdateTagRequest,
@@ -45,7 +45,13 @@ pub trait TagRepoService: Send + Sync + 'static {
#[derive(Clone)] #[derive(Clone)]
pub struct TagRepoServiceImpl { pub struct TagRepoServiceImpl {
pub db: DatabaseConnection, db: DatabaseConnection,
}
impl TagRepoServiceImpl {
pub fn new(db: DatabaseConnection) -> Self {
Self { db }
}
} }
#[async_trait::async_trait] #[async_trait::async_trait]

View File

@@ -6,8 +6,8 @@ use thiserror::Error;
use crate::{ use crate::{
db::{Db, DbServiceError}, db::{Db, DbServiceError},
services::transaction::tag::{ services::transaction::tag::{
repo::{TagRepoService, TagRepoServiceImpl},
CreateTagRequest, Tag, UpdateTagRequest, CreateTagRequest, Tag, UpdateTagRequest,
repo::{TagRepoService, TagRepoServiceImpl},
}, },
}; };
@@ -67,7 +67,7 @@ impl TagServiceImpl<TagRepoServiceImpl> {
pub fn new(db: DatabaseConnection) -> Self { pub fn new(db: DatabaseConnection) -> Self {
Self { Self {
db: db.clone(), db: db.clone(),
tag_repo: Arc::new(TagRepoServiceImpl { db }), tag_repo: Arc::new(TagRepoServiceImpl::new(db)),
} }
} }
} }