refactor(di): migrate from setter to constructor injection for logService
All checks were successful
Build Backend / build (push) Successful in 12m35s
Build Backend / build-docker (push) Successful in 1m2s

- Remove SetLogService methods from user, post, comment, and admin post services
- Add logService as constructor parameter to all dependent services
- Centralize call-related and message error definitions in app_errors.go
- Add ConversationID field to WSEventResponse for improved message tracking
- Simplify wire provider functions by removing manual setter calls
This commit is contained in:
lafay
2026-03-28 07:03:21 +08:00
parent d357998321
commit 736344f123
15 changed files with 203 additions and 254 deletions

View File

@@ -39,18 +39,6 @@ func InitializeApp() (*App, error) {
systemMessageService := wire.ProvideSystemMessageService(systemNotificationRepository, pushService, userRepository, postRepository, cache)
emailClient := wire.ProvideEmailClient(config)
emailService := wire.ProvideEmailService(emailClient)
userService := wire.ProvideUserService(userRepository, systemMessageService, emailService, cache)
userActivityRepository := wire.ProvideUserActivityRepository(db, cache)
userActivityService := wire.ProvideUserActivityService(userActivityRepository)
openaiClient := wire.ProvideOpenAIClient(config)
postAIService := wire.ProvidePostAIService(openaiClient)
transactionManager := wire.ProvideTransactionManager(db)
manager := wire.ProvideHookManager()
commentRepository := repository.NewCommentRepository(db)
moderationHooks := wire.ProvideModerationHooks(manager, postAIService, postRepository, commentRepository, config)
builtinHooks := wire.ProvideBuiltinHooks(manager)
postService := wire.ProvidePostService(postRepository, systemMessageService, postAIService, cache, transactionManager, manager, moderationHooks, builtinHooks)
commentService := wire.ProvideCommentService(commentRepository, postRepository, systemMessageService, postAIService, cache, manager)
operationLogRepository := repository.NewOperationLogRepository(db)
loginLogRepository := repository.NewLoginLogRepository(db)
dataChangeLogRepository := repository.NewDataChangeLogRepository(db)
@@ -60,10 +48,22 @@ func InitializeApp() (*App, error) {
loginLogService := wire.ProvideLoginLogService(asyncLogManager, loginLogRepository)
dataChangeLogService := wire.ProvideDataChangeLogService(asyncLogManager, dataChangeLogRepository)
logService := wire.ProvideLogService(operationLogService, loginLogService, dataChangeLogService)
userHandler := wire.ProvideUserHandler(userService, userActivityService, postService, commentService, logService)
userService := wire.ProvideUserService(userRepository, systemMessageService, emailService, cache, logService)
userActivityRepository := wire.ProvideUserActivityRepository(db, cache)
userActivityService := wire.ProvideUserActivityService(userActivityRepository)
userHandler := handler.NewUserHandler(userService, userActivityService, logService)
openaiClient := wire.ProvideOpenAIClient(config)
postAIService := wire.ProvidePostAIService(openaiClient)
transactionManager := wire.ProvideTransactionManager(db)
manager := wire.ProvideHookManager()
commentRepository := repository.NewCommentRepository(db)
moderationHooks := wire.ProvideModerationHooks(manager, postAIService, postRepository, commentRepository, config)
builtinHooks := wire.ProvideBuiltinHooks(manager)
postService := wire.ProvidePostService(postRepository, systemMessageService, postAIService, cache, transactionManager, manager, moderationHooks, builtinHooks, logService)
channelRepository := repository.NewChannelRepository(db)
channelService := wire.ProvideChannelService(channelRepository, cache)
postHandler := wire.ProvidePostHandler(postService, userService, channelService, logService)
postHandler := handler.NewPostHandler(postService, userService, channelService)
commentService := wire.ProvideCommentService(commentRepository, postRepository, systemMessageService, postAIService, cache, manager, logService)
commentHandler := handler.NewCommentHandler(commentService)
s3Client, err := wire.ProvideS3Client(config)
if err != nil {
@@ -104,7 +104,7 @@ func InitializeApp() (*App, error) {
roleHandler := handler.NewRoleHandler(roleService)
adminUserService := wire.ProvideAdminUserService(userRepository)
adminUserHandler := handler.NewAdminUserHandler(adminUserService)
adminPostService := wire.ProvideAdminPostService(postRepository, cache)
adminPostService := wire.ProvideAdminPostService(postRepository, cache, logService)
adminPostHandler := handler.NewAdminPostHandler(adminPostService)
adminCommentService := wire.ProvideAdminCommentService(commentRepository, postRepository)
adminCommentHandler := handler.NewAdminCommentHandler(adminCommentService)
@@ -117,10 +117,10 @@ func InitializeApp() (*App, error) {
qrCodeHandler := handler.NewQRCodeHandler(qrCodeLoginService)
materialSubjectRepository := repository.NewMaterialSubjectRepository(db)
materialFileRepository := repository.NewMaterialFileRepository(db)
callRepository := repository.NewCallRepository(db)
materialService := wire.ProvideMaterialService(materialSubjectRepository, materialFileRepository)
callService := wire.ProvideCallService(callRepository, hub, config, db)
materialHandler := handler.NewMaterialHandler(materialService)
callRepository := repository.NewCallRepository(db)
callService := wire.ProvideCallService(callRepository, hub, config, db)
callHandler := handler.NewCallHandler(callService)
wsHandler := wire.ProvideWSHandler(hub, chatService, groupService, jwtService, callService)
router := ProvideRouter(userHandler, postHandler, commentHandler, messageHandler, notificationHandler, uploadHandler, jwtService, pushHandler, systemMessageHandler, groupHandler, stickerHandler, voteHandler, channelHandler, scheduleHandler, roleHandler, adminUserHandler, adminPostHandler, adminCommentHandler, adminGroupHandler, adminDashboardHandler, adminLogHandler, qrCodeHandler, materialHandler, callHandler, logService, userActivityService, casbinService, wsHandler)