Files
backend/internal/handler/report_handler.go
lafay 2f584c1f2c
All checks were successful
Build Backend / build (push) Successful in 5m10s
Build Backend / build-docker (push) Successful in 2m22s
This is a breaking change that renames the entire project from "Carrot BBS" to "WithYou".
The Go module name has been changed from `carrot_bbs` to `with_you`, which requires
all import paths to be updated throughout the codebase and by external consumers.

BREAKING CHANGE: Module name changed from carrot_bbs to with_you. All imports
and dependencies must be updated from carrot_bbs/* to with_you/*.
2026-04-22 16:01:59 +08:00

61 lines
1.3 KiB
Go

package handler
import (
"with_you/internal/dto"
"with_you/internal/pkg/response"
"with_you/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, 500, err.Error())
return
}
response.Success(c, dto.ConvertReportToResponse(report))
}