This commit performs a significant cleanup of the codebase by removing unused functions, methods, and entire files across various internal modules. This reduces technical debt and simplifies the project structure. Key changes include: - **cache**: Removed unused cache key generators and metrics snapshots. - **dto**: Removed redundant converter functions and segment creation helpers. - **middleware**: Deleted the unused `logger.go` middleware and simplified `ratelimit.go` and `casbin.go`. - **model**: Removed unused ID helpers, database closing functions, and batch decryption logic. - **pkg**: Cleaned up unused utility functions in `circuitbreaker`, `crypto`, `cursor`, `hook`, and `utils`. - **service**: Deleted `account_cleanup_service.go` and removed unused helper functions in `log_cleanup_service.go` and `sensitive_service.go`. - **repository**: Removed unused private loading methods in `comment_repo.go`.
140 lines
3.2 KiB
Go
140 lines
3.2 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"
|
|
)
|
|
|
|
// AdminReportHandler 管理端举报处理器
|
|
type AdminReportHandler struct {
|
|
adminReportService service.AdminReportService
|
|
}
|
|
|
|
// NewAdminReportHandler 创建管理端举报处理器
|
|
func NewAdminReportHandler(adminReportService service.AdminReportService) *AdminReportHandler {
|
|
return &AdminReportHandler{
|
|
adminReportService: adminReportService,
|
|
}
|
|
}
|
|
|
|
// List 获取举报列表
|
|
func (h *AdminReportHandler) List(c *gin.Context) {
|
|
// 解析查询参数
|
|
var query dto.AdminReportListQuery
|
|
if err := c.ShouldBindQuery(&query); err != nil {
|
|
response.BadRequest(c, "参数错误: "+err.Error())
|
|
return
|
|
}
|
|
|
|
// 设置默认分页
|
|
if query.Page == 0 {
|
|
query.Page = 1
|
|
}
|
|
if query.PageSize == 0 {
|
|
query.PageSize = 20
|
|
}
|
|
|
|
// 查询列表
|
|
reports, total, err := h.adminReportService.GetReportList(c.Request.Context(), query)
|
|
if err != nil {
|
|
zap.L().Error("failed to get report list", zap.Error(err))
|
|
response.InternalServerError(c, "获取举报列表失败")
|
|
return
|
|
}
|
|
|
|
response.Paginated(c, reports, total, query.Page, query.PageSize)
|
|
}
|
|
|
|
// Detail 获取举报详情
|
|
func (h *AdminReportHandler) Detail(c *gin.Context) {
|
|
// 获取举报ID
|
|
id := c.Param("id")
|
|
if id == "" {
|
|
response.BadRequest(c, "举报ID不能为空")
|
|
return
|
|
}
|
|
|
|
// 查询详情
|
|
report, err := h.adminReportService.GetReportDetail(c.Request.Context(), id)
|
|
if err != nil {
|
|
zap.L().Error("failed to get report detail", zap.Error(err), zap.String("id", id))
|
|
response.NotFound(c, "举报不存在")
|
|
return
|
|
}
|
|
|
|
response.Success(c, report)
|
|
}
|
|
|
|
// Handle 处理举报
|
|
func (h *AdminReportHandler) Handle(c *gin.Context) {
|
|
// 获取处理人ID
|
|
handledBy := c.GetString("user_id")
|
|
if handledBy == "" {
|
|
response.Unauthorized(c, "未授权")
|
|
return
|
|
}
|
|
|
|
// 获取举报ID
|
|
id := c.Param("id")
|
|
if id == "" {
|
|
response.BadRequest(c, "举报ID不能为空")
|
|
return
|
|
}
|
|
|
|
// 解析请求
|
|
var req dto.HandleReportRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "参数错误: "+err.Error())
|
|
return
|
|
}
|
|
|
|
// 处理举报
|
|
err := h.adminReportService.HandleReport(c.Request.Context(), id, req.Action, req.Result, handledBy)
|
|
if err != nil {
|
|
zap.L().Error("failed to handle report",
|
|
zap.Error(err),
|
|
zap.String("id", id),
|
|
zap.String("action", req.Action),
|
|
)
|
|
response.Error(c, 500, err.Error())
|
|
return
|
|
}
|
|
|
|
response.Success(c, gin.H{"message": "处理成功"})
|
|
}
|
|
|
|
// BatchHandle 批量处理举报
|
|
func (h *AdminReportHandler) BatchHandle(c *gin.Context) {
|
|
// 获取处理人ID
|
|
handledBy := c.GetString("user_id")
|
|
if handledBy == "" {
|
|
response.Unauthorized(c, "未授权")
|
|
return
|
|
}
|
|
|
|
// 解析请求
|
|
var req dto.BatchHandleReportRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "参数错误: "+err.Error())
|
|
return
|
|
}
|
|
|
|
// 批量处理
|
|
result, err := h.adminReportService.BatchHandle(c.Request.Context(), req.IDs, req.Action, req.Result, handledBy)
|
|
if err != nil {
|
|
zap.L().Error("failed to batch handle reports",
|
|
zap.Error(err),
|
|
zap.Int("count", len(req.IDs)),
|
|
)
|
|
response.Error(c, 500, err.Error())
|
|
return
|
|
}
|
|
|
|
response.Success(c, result)
|
|
}
|
|
|