Files
backend/internal/handler/report_handler.go
lafay a69b2026f4
All checks were successful
Build Backend / build (push) Successful in 13m27s
Build Backend / build-docker (push) Successful in 1m29s
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.
2026-03-30 03:44:24 +08:00

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, 500, err.Error())
return
}
response.Success(c, dto.ConvertReportToResponse(report))
}