diff --git a/cmd/server/wire.go b/cmd/server/wire.go index 46125f7..f19c4a7 100644 --- a/cmd/server/wire.go +++ b/cmd/server/wire.go @@ -48,6 +48,8 @@ func ProvideRouter( qrcodeHandler *handler.QRCodeHandler, materialHandler *handler.MaterialHandler, callHandler *handler.CallHandler, + reportHandler *handler.ReportHandler, + adminReportHandler *handler.AdminReportHandler, logService *service.LogService, activityService service.UserActivityService, casbinService service.CasbinService, @@ -78,6 +80,8 @@ func ProvideRouter( qrcodeHandler, materialHandler, callHandler, + reportHandler, + adminReportHandler, logService, activityService, casbinService, diff --git a/cmd/server/wire_gen.go b/cmd/server/wire_gen.go index b7407cf..62ca35d 100644 --- a/cmd/server/wire_gen.go +++ b/cmd/server/wire_gen.go @@ -122,8 +122,13 @@ func InitializeApp() (*App, error) { callRepository := repository.NewCallRepository(db) callService := wire.ProvideCallService(callRepository, hub, config, db) callHandler := handler.NewCallHandler(callService) + reportRepository := repository.NewReportRepository(db) + reportService := wire.ProvideReportService(reportRepository, postRepository, commentRepository, messageRepository, userRepository, systemNotificationRepository, pushService, transactionManager, operationLogService, config) + reportHandler := handler.NewReportHandler(reportService) + adminReportService := wire.ProvideAdminReportService(reportRepository, postRepository, commentRepository, messageRepository, userRepository, systemNotificationRepository, pushService, transactionManager, operationLogService) + adminReportHandler := handler.NewAdminReportHandler(adminReportService) 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) + 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, reportHandler, adminReportHandler, logService, userActivityService, casbinService, wsHandler) hotRankWorker := wire.ProvideHotRankWorker(config, postRepository, cache) app := NewApp(config, db, router, pushService, hotRankWorker, server, logger) return app, nil @@ -157,6 +162,8 @@ func ProvideRouter( qrcodeHandler *handler.QRCodeHandler, materialHandler *handler.MaterialHandler, callHandler *handler.CallHandler, + reportHandler *handler.ReportHandler, + adminReportHandler *handler.AdminReportHandler, logService *service.LogService, activityService service.UserActivityService, casbinService service.CasbinService, @@ -187,6 +194,8 @@ func ProvideRouter( qrcodeHandler, materialHandler, callHandler, + reportHandler, + adminReportHandler, logService, activityService, casbinService, diff --git a/internal/handler/admin_report_handler.go b/internal/handler/admin_report_handler.go index 4478d98..1b0278a 100644 --- a/internal/handler/admin_report_handler.go +++ b/internal/handler/admin_report_handler.go @@ -101,7 +101,7 @@ func (h *AdminReportHandler) Handle(c *gin.Context) { zap.String("id", id), zap.String("action", req.Action), ) - response.Error(c, err.Error()) + response.Error(c, 500, err.Error()) return } @@ -131,7 +131,7 @@ func (h *AdminReportHandler) BatchHandle(c *gin.Context) { zap.Error(err), zap.Int("count", len(req.IDs)), ) - response.Error(c, err.Error()) + response.Error(c, 500, err.Error()) return } diff --git a/internal/handler/report_handler.go b/internal/handler/report_handler.go index 848062a..a01e2ef 100644 --- a/internal/handler/report_handler.go +++ b/internal/handler/report_handler.go @@ -53,7 +53,7 @@ func (h *ReportHandler) Create(c *gin.Context) { zap.String("target_type", req.TargetType), zap.String("target_id", req.TargetID), ) - response.Error(c, err.Error()) + response.Error(c, 500, err.Error()) return } diff --git a/internal/service/admin_report_service.go b/internal/service/admin_report_service.go index 52563df..e1f0820 100644 --- a/internal/service/admin_report_service.go +++ b/internal/service/admin_report_service.go @@ -379,13 +379,7 @@ func (s *adminReportServiceImpl) deleteTargetContent(ctx context.Context, target // notifyReporter 通知举报人 func (s *adminReportServiceImpl) notifyReporter(ctx context.Context, report *model.Report, action, result string) { - if s.systemNotify == nil { - return - } - - // 获取举报人信息 - reporter, err := s.userRepo.GetByID(report.ReporterID) - if err != nil { + if s.notifyRepo == nil { return } @@ -408,22 +402,26 @@ func (s *adminReportServiceImpl) notifyReporter(ctx context.Context, report *mod } } - // 发送通知 - _, err = s.systemNotify.CreateNotification(ctx, &model.SystemNotification{ + // 创建通知 + notification := &model.SystemNotification{ ReceiverID: report.ReporterID, - Type: notifyType, - Title: title, - Content: content, + Type: notifyType, + Title: title, + Content: content, ExtraData: &model.SystemNotificationExtra{ - ActorIDStr: report.ReporterID, - ActorName: reporter.Nickname, - TargetID: report.TargetID, - TargetType: string(report.TargetType), + ActorIDStr: report.ReporterID, + TargetID: report.TargetID, + TargetType: string(report.TargetType), }, - }) + } - if err != nil { - zap.L().Error("failed to send report notification", zap.Error(err)) + if err := s.notifyRepo.Create(notification); err != nil { + zap.L().Error("failed to create notification", zap.Error(err)) + } + + // 推送通知 + if s.pushService != nil { + s.pushService.PushSystemNotification(ctx, report.ReporterID, notification) } } @@ -464,14 +462,9 @@ func extractTextFromSegments(segments model.MessageSegments) string { } // convertUserToBrief 将用户模型转换为举报用的简要信息 -func convertUserToBrief(user *model.User) *dto.ReportUserBrief { +func convertUserToBrief(user *model.User) *dto.UserResponse { if user == nil { return nil } - return &dto.ReportUserBrief{ - ID: user.ID, - Username: user.Username, - Nickname: user.Nickname, - Avatar: user.Avatar, - } + return dto.ConvertUserToResponse(user) } \ No newline at end of file diff --git a/internal/wire/service.go b/internal/wire/service.go index e19e307..c4dda22 100644 --- a/internal/wire/service.go +++ b/internal/wire/service.go @@ -404,12 +404,13 @@ func ProvideReportService( commentRepo repository.CommentRepository, messageRepo repository.MessageRepository, userRepo repository.UserRepository, - systemNotify service.SystemNotificationService, + notifyRepo repository.SystemNotificationRepository, + pushService service.PushService, txManager repository.TransactionManager, - logService *service.LogService, + logService service.OperationLogService, cfg *config.Config, ) service.ReportService { - return service.NewReportService(reportRepo, postRepo, commentRepo, messageRepo, userRepo, systemNotify, txManager, logService, cfg) + return service.NewReportService(reportRepo, postRepo, commentRepo, messageRepo, userRepo, notifyRepo, pushService, txManager, logService, cfg) } // ProvideAdminReportService 提供管理端举报服务 @@ -419,9 +420,10 @@ func ProvideAdminReportService( commentRepo repository.CommentRepository, messageRepo repository.MessageRepository, userRepo repository.UserRepository, - systemNotify service.SystemNotificationService, + notifyRepo repository.SystemNotificationRepository, + pushService service.PushService, txManager repository.TransactionManager, - logService *service.LogService, + logService service.OperationLogService, ) service.AdminReportService { - return service.NewAdminReportService(reportRepo, postRepo, commentRepo, messageRepo, userRepo, systemNotify, txManager, logService) + return service.NewAdminReportService(reportRepo, postRepo, commentRepo, messageRepo, userRepo, notifyRepo, pushService, txManager, logService) }