Initial commit: CarrotAssistant backend (Go + Gin + SQLite, OpenAI-compatible agent runtime)
This commit is contained in:
29
internal/server/handlers_audit.go
Normal file
29
internal/server/handlers_audit.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"code.littlelan.cn/CarrotAssistant/backend/internal/store"
|
||||
)
|
||||
|
||||
// GET /admin/audit-logs — optional ?app_id= and ?action= filters, ?limit=
|
||||
// capped at 500 for safety.
|
||||
func (d Deps) handleListAuditLogs(c *gin.Context) {
|
||||
q := d.DB.Model(&store.AuditLog{}).Order("id DESC")
|
||||
if a := c.Query("app_id"); a != "" {
|
||||
q = q.Where("app_id = ?", a)
|
||||
}
|
||||
if act := c.Query("action"); act != "" {
|
||||
q = q.Where("action = ?", act)
|
||||
}
|
||||
limit := 200
|
||||
if n, err := strconv.Atoi(c.Query("limit")); err == nil && n > 0 && n <= 500 {
|
||||
limit = n
|
||||
}
|
||||
var logs []store.AuditLog
|
||||
q.Limit(limit).Find(&logs)
|
||||
c.JSON(http.StatusOK, logs)
|
||||
}
|
||||
Reference in New Issue
Block a user