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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user