Files
backend/internal/handler/report_handler.go
lafay 67a5660952
All checks were successful
Build Backend / build (push) Successful in 3m54s
Build Backend / build-docker (push) Successful in 1m9s
refactor: unify code formatting and improve push/search implementations
- Remove BOM from all Go source files
- Standardize import ordering and whitespace across handlers and services
- Replace PostgreSQL full-text search with ILIKE pattern matching in post and user repositories
- Enhance JPush client with TLS transport, rate limit monitoring, and simplified API
- Refactor PushService to include userID in device management methods
- Add MaxDevicesPerUser limit and extract helper functions for push payload construction
2026-04-28 14:53:04 +08:00

62 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))
}