refactor: update repository interfaces and improve dependency injection
All checks were successful
Build Backend / build (push) Successful in 12m45s
Build Backend / build-docker (push) Successful in 2m40s

- Refactored repository structures to use interfaces instead of concrete types, enhancing flexibility and testability.
- Updated various repository methods to accept interfaces, allowing for better dependency management.
- Modified wire generation to accommodate new repository interfaces, ensuring proper service injection throughout the application.
- Enhanced handler methods to utilize DTOs for filtering and data handling, improving code clarity and maintainability.
This commit is contained in:
lafay
2026-03-26 18:14:16 +08:00
parent 7b41dfeb00
commit c6848aba06
50 changed files with 1034 additions and 663 deletions

View File

@@ -13,7 +13,7 @@ import (
type PostModerationHook struct {
name string
postAIService PostAIService
postRepo *repository.PostRepository
postRepo repository.PostRepository
strictMode bool
}
@@ -23,7 +23,7 @@ type PostAIService interface {
ModerateComment(ctx context.Context, content string, images []string) error
}
func NewPostModerationHook(postAIService PostAIService, postRepo *repository.PostRepository, strictMode bool) *PostModerationHook {
func NewPostModerationHook(postAIService PostAIService, postRepo repository.PostRepository, strictMode bool) *PostModerationHook {
return &PostModerationHook{
name: "moderation.post.ai",
postAIService: postAIService,
@@ -107,11 +107,11 @@ func (h *PostModerationHook) Execute(ctx *HookContext) error {
type CommentModerationHook struct {
name string
postAIService PostAIService
commentRepo *repository.CommentRepository
commentRepo repository.CommentRepository
strictMode bool
}
func NewCommentModerationHook(postAIService PostAIService, commentRepo *repository.CommentRepository, strictMode bool) *CommentModerationHook {
func NewCommentModerationHook(postAIService PostAIService, commentRepo repository.CommentRepository, strictMode bool) *CommentModerationHook {
return &CommentModerationHook{
name: "moderation.comment.ai",
postAIService: postAIService,
@@ -300,8 +300,8 @@ func (h *SensitiveWordHook) executeComment(ctx *HookContext) error {
type ModerationHooks struct {
postAIService PostAIService
sensitiveService SensitiveService
postRepo *repository.PostRepository
commentRepo *repository.CommentRepository
postRepo repository.PostRepository
commentRepo repository.CommentRepository
strictMode bool
replaceStr string
}
@@ -309,8 +309,8 @@ type ModerationHooks struct {
func NewModerationHooks(
postAIService PostAIService,
sensitiveService SensitiveService,
postRepo *repository.PostRepository,
commentRepo *repository.CommentRepository,
postRepo repository.PostRepository,
commentRepo repository.CommentRepository,
strictMode bool,
replaceStr string,
) *ModerationHooks {