feat(report): integrate report handling into application
All checks were successful
Build Backend / build (push) Successful in 13m27s
Build Backend / build-docker (push) Successful in 1m29s

- Added Report and AdminReport handlers to manage report-related functionalities.
- Updated router and wire generation to include new report services and handlers.
- Enhanced error handling in report and admin report handlers to return appropriate status codes.
- Refactored notification logic in admin report service to utilize a dedicated notification repository and push service.
This commit is contained in:
lafay
2026-03-30 03:44:24 +08:00
parent 7fa49155dd
commit a69b2026f4
6 changed files with 44 additions and 36 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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,
ExtraData: &model.SystemNotificationExtra{
ActorIDStr: report.ReporterID,
ActorName: reporter.Nickname,
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)
}

View File

@@ -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)
}