- Removed unused time imports from report DTO and service files. - Updated import paths for response handling in admin and general report handlers. - Refactored logging methods in admin and report services to use a unified operation logging approach. - Introduced helper functions for extracting text from message segments and converting user models to brief report information.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"carrot_bbs/internal/dto"
|
|
"carrot_bbs/internal/pkg/response"
|
|
"carrot_bbs/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// ReportHandler 举报处理器
|
|
type ReportHandler struct {
|
|
reportService service.ReportService
|
|
}
|
|
|
|
// NewReportHandler 创建举报处理器
|
|
func NewReportHandler(reportService service.ReportService) *ReportHandler {
|
|
return &ReportHandler{
|
|
reportService: reportService,
|
|
}
|
|
}
|
|
|
|
// Create 创建举报
|
|
func (h *ReportHandler) Create(c *gin.Context) {
|
|
// 获取用户ID
|
|
userID := c.GetString("user_id")
|
|
if userID == "" {
|
|
response.Unauthorized(c, "未授权")
|
|
return
|
|
}
|
|
|
|
// 解析请求
|
|
var req dto.CreateReportRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "参数错误: "+err.Error())
|
|
return
|
|
}
|
|
|
|
// 创建举报
|
|
report, err := h.reportService.CreateReport(
|
|
c.Request.Context(),
|
|
userID,
|
|
req.TargetType,
|
|
req.TargetID,
|
|
req.Reason,
|
|
req.Description,
|
|
)
|
|
if err != nil {
|
|
zap.L().Error("failed to create report",
|
|
zap.Error(err),
|
|
zap.String("user_id", userID),
|
|
zap.String("target_type", req.TargetType),
|
|
zap.String("target_id", req.TargetID),
|
|
)
|
|
response.Error(c, err.Error())
|
|
return
|
|
}
|
|
|
|
response.Success(c, dto.ConvertReportToResponse(report))
|
|
} |