feat(report): integrate report handling into application
- 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:
@@ -48,6 +48,8 @@ func ProvideRouter(
|
|||||||
qrcodeHandler *handler.QRCodeHandler,
|
qrcodeHandler *handler.QRCodeHandler,
|
||||||
materialHandler *handler.MaterialHandler,
|
materialHandler *handler.MaterialHandler,
|
||||||
callHandler *handler.CallHandler,
|
callHandler *handler.CallHandler,
|
||||||
|
reportHandler *handler.ReportHandler,
|
||||||
|
adminReportHandler *handler.AdminReportHandler,
|
||||||
logService *service.LogService,
|
logService *service.LogService,
|
||||||
activityService service.UserActivityService,
|
activityService service.UserActivityService,
|
||||||
casbinService service.CasbinService,
|
casbinService service.CasbinService,
|
||||||
@@ -78,6 +80,8 @@ func ProvideRouter(
|
|||||||
qrcodeHandler,
|
qrcodeHandler,
|
||||||
materialHandler,
|
materialHandler,
|
||||||
callHandler,
|
callHandler,
|
||||||
|
reportHandler,
|
||||||
|
adminReportHandler,
|
||||||
logService,
|
logService,
|
||||||
activityService,
|
activityService,
|
||||||
casbinService,
|
casbinService,
|
||||||
|
|||||||
@@ -122,8 +122,13 @@ func InitializeApp() (*App, error) {
|
|||||||
callRepository := repository.NewCallRepository(db)
|
callRepository := repository.NewCallRepository(db)
|
||||||
callService := wire.ProvideCallService(callRepository, hub, config, db)
|
callService := wire.ProvideCallService(callRepository, hub, config, db)
|
||||||
callHandler := handler.NewCallHandler(callService)
|
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)
|
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)
|
hotRankWorker := wire.ProvideHotRankWorker(config, postRepository, cache)
|
||||||
app := NewApp(config, db, router, pushService, hotRankWorker, server, logger)
|
app := NewApp(config, db, router, pushService, hotRankWorker, server, logger)
|
||||||
return app, nil
|
return app, nil
|
||||||
@@ -157,6 +162,8 @@ func ProvideRouter(
|
|||||||
qrcodeHandler *handler.QRCodeHandler,
|
qrcodeHandler *handler.QRCodeHandler,
|
||||||
materialHandler *handler.MaterialHandler,
|
materialHandler *handler.MaterialHandler,
|
||||||
callHandler *handler.CallHandler,
|
callHandler *handler.CallHandler,
|
||||||
|
reportHandler *handler.ReportHandler,
|
||||||
|
adminReportHandler *handler.AdminReportHandler,
|
||||||
logService *service.LogService,
|
logService *service.LogService,
|
||||||
activityService service.UserActivityService,
|
activityService service.UserActivityService,
|
||||||
casbinService service.CasbinService,
|
casbinService service.CasbinService,
|
||||||
@@ -187,6 +194,8 @@ func ProvideRouter(
|
|||||||
qrcodeHandler,
|
qrcodeHandler,
|
||||||
materialHandler,
|
materialHandler,
|
||||||
callHandler,
|
callHandler,
|
||||||
|
reportHandler,
|
||||||
|
adminReportHandler,
|
||||||
logService,
|
logService,
|
||||||
activityService,
|
activityService,
|
||||||
casbinService,
|
casbinService,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (h *AdminReportHandler) Handle(c *gin.Context) {
|
|||||||
zap.String("id", id),
|
zap.String("id", id),
|
||||||
zap.String("action", req.Action),
|
zap.String("action", req.Action),
|
||||||
)
|
)
|
||||||
response.Error(c, err.Error())
|
response.Error(c, 500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ func (h *AdminReportHandler) BatchHandle(c *gin.Context) {
|
|||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
zap.Int("count", len(req.IDs)),
|
zap.Int("count", len(req.IDs)),
|
||||||
)
|
)
|
||||||
response.Error(c, err.Error())
|
response.Error(c, 500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (h *ReportHandler) Create(c *gin.Context) {
|
|||||||
zap.String("target_type", req.TargetType),
|
zap.String("target_type", req.TargetType),
|
||||||
zap.String("target_id", req.TargetID),
|
zap.String("target_id", req.TargetID),
|
||||||
)
|
)
|
||||||
response.Error(c, err.Error())
|
response.Error(c, 500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -379,13 +379,7 @@ func (s *adminReportServiceImpl) deleteTargetContent(ctx context.Context, target
|
|||||||
|
|
||||||
// notifyReporter 通知举报人
|
// notifyReporter 通知举报人
|
||||||
func (s *adminReportServiceImpl) notifyReporter(ctx context.Context, report *model.Report, action, result string) {
|
func (s *adminReportServiceImpl) notifyReporter(ctx context.Context, report *model.Report, action, result string) {
|
||||||
if s.systemNotify == nil {
|
if s.notifyRepo == nil {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取举报人信息
|
|
||||||
reporter, err := s.userRepo.GetByID(report.ReporterID)
|
|
||||||
if err != nil {
|
|
||||||
return
|
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,
|
ReceiverID: report.ReporterID,
|
||||||
Type: notifyType,
|
Type: notifyType,
|
||||||
Title: title,
|
Title: title,
|
||||||
Content: content,
|
Content: content,
|
||||||
ExtraData: &model.SystemNotificationExtra{
|
ExtraData: &model.SystemNotificationExtra{
|
||||||
ActorIDStr: report.ReporterID,
|
ActorIDStr: report.ReporterID,
|
||||||
ActorName: reporter.Nickname,
|
TargetID: report.TargetID,
|
||||||
TargetID: report.TargetID,
|
TargetType: string(report.TargetType),
|
||||||
TargetType: string(report.TargetType),
|
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err := s.notifyRepo.Create(notification); err != nil {
|
||||||
zap.L().Error("failed to send report notification", zap.Error(err))
|
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 将用户模型转换为举报用的简要信息
|
// convertUserToBrief 将用户模型转换为举报用的简要信息
|
||||||
func convertUserToBrief(user *model.User) *dto.ReportUserBrief {
|
func convertUserToBrief(user *model.User) *dto.UserResponse {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &dto.ReportUserBrief{
|
return dto.ConvertUserToResponse(user)
|
||||||
ID: user.ID,
|
|
||||||
Username: user.Username,
|
|
||||||
Nickname: user.Nickname,
|
|
||||||
Avatar: user.Avatar,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -404,12 +404,13 @@ func ProvideReportService(
|
|||||||
commentRepo repository.CommentRepository,
|
commentRepo repository.CommentRepository,
|
||||||
messageRepo repository.MessageRepository,
|
messageRepo repository.MessageRepository,
|
||||||
userRepo repository.UserRepository,
|
userRepo repository.UserRepository,
|
||||||
systemNotify service.SystemNotificationService,
|
notifyRepo repository.SystemNotificationRepository,
|
||||||
|
pushService service.PushService,
|
||||||
txManager repository.TransactionManager,
|
txManager repository.TransactionManager,
|
||||||
logService *service.LogService,
|
logService service.OperationLogService,
|
||||||
cfg *config.Config,
|
cfg *config.Config,
|
||||||
) service.ReportService {
|
) 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 提供管理端举报服务
|
// ProvideAdminReportService 提供管理端举报服务
|
||||||
@@ -419,9 +420,10 @@ func ProvideAdminReportService(
|
|||||||
commentRepo repository.CommentRepository,
|
commentRepo repository.CommentRepository,
|
||||||
messageRepo repository.MessageRepository,
|
messageRepo repository.MessageRepository,
|
||||||
userRepo repository.UserRepository,
|
userRepo repository.UserRepository,
|
||||||
systemNotify service.SystemNotificationService,
|
notifyRepo repository.SystemNotificationRepository,
|
||||||
|
pushService service.PushService,
|
||||||
txManager repository.TransactionManager,
|
txManager repository.TransactionManager,
|
||||||
logService *service.LogService,
|
logService service.OperationLogService,
|
||||||
) service.AdminReportService {
|
) 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user