Some checks failed
CI / Build & Test (push) Failing after 33s
- 37 个端点全部添加 godoc Swagger 注解(RBAC 11 / Org 5 / Audit 1 / Settings 7 / Notification 7) - 重新生成 docs/(swagger.json/yaml/docs.go) - M8 质量横切:IP 限流、安全头、Body 限制、结构化日志增强、优雅关闭 - 新增 Dockerfile 多阶段构建 + .dockerignore - 新增 testutil 测试工具包 - 修复 testutil.go 编译错误
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package interfaces
|
||
|
||
import (
|
||
"strconv"
|
||
|
||
"mengstack/internal/kernel/response"
|
||
"mengstack/internal/kernel/tenant"
|
||
"mengstack/internal/modules/audit/application"
|
||
auditdomain "mengstack/internal/modules/audit/domain"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
type Handler struct {
|
||
svc *application.Service
|
||
}
|
||
|
||
func NewHandler(svc *application.Service) *Handler {
|
||
return &Handler{svc: svc}
|
||
}
|
||
|
||
// ListLogs godoc
|
||
// @Summary 查询审计日志
|
||
// @Description 分页查询审计日志,支持按用户、操作、资源筛选
|
||
// @Tags Audit
|
||
// @Produce json
|
||
// @Param user_id query int false "按用户 ID 筛选"
|
||
// @Param action query string false "按操作筛选"
|
||
// @Param resource query string false "按资源类型筛选"
|
||
// @Param page query int false "页码(默认 1)"
|
||
// @Param page_size query int false "每页条数(默认 20)"
|
||
// @Success 200 {object} response.Response
|
||
// @Failure 500 {object} response.Response
|
||
// @Security Bearer
|
||
// @Security TenantID
|
||
// @Router /api/v1/audit/logs [get]
|
||
func (h *Handler) ListLogs(c *gin.Context) {
|
||
tenantID, _ := tenant.FromContext(c.Request.Context())
|
||
|
||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||
|
||
query := auditdomain.AuditQuery{
|
||
TenantID: tenantID,
|
||
UserID: parseUintQuery(c, "user_id"),
|
||
Action: c.Query("action"),
|
||
Resource: c.Query("resource"),
|
||
Page: page,
|
||
PageSize: pageSize,
|
||
}
|
||
|
||
dtos, total, err := h.svc.Query(c.Request.Context(), query)
|
||
if err != nil {
|
||
response.HandleError(c, err)
|
||
return
|
||
}
|
||
|
||
response.Success(c, gin.H{
|
||
"items": dtos,
|
||
"total": total,
|
||
"page": page,
|
||
})
|
||
}
|
||
|
||
func parseUintQuery(c *gin.Context, key string) uint {
|
||
v, _ := strconv.ParseUint(c.DefaultQuery(key, "0"), 10, 64)
|
||
return uint(v)
|
||
}
|