46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
postgresstore "knowledge-governance/internal/platform/postgres"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
type sourceAuditReader interface {
|
|
ListSourceAudit(context.Context, int, int) (postgresstore.SourceAuditPage, error)
|
|
}
|
|
|
|
func listSourceAudit(w http.ResponseWriter, r *http.Request, config Config) {
|
|
if _, ok := requireSessionIdentity(w, r); !ok {
|
|
return
|
|
}
|
|
limit, offset := 100, 0
|
|
for key, target := range map[string]*int{"limit": &limit, "offset": &offset} {
|
|
if value := r.URL.Query().Get(key); value != "" {
|
|
n, err := strconv.Atoi(value)
|
|
if err != nil {
|
|
writeJSON(w, 400, map[string]string{"error": "invalid pagination"})
|
|
return
|
|
}
|
|
*target = n
|
|
}
|
|
}
|
|
if limit < 1 || limit > 100 || offset < 0 {
|
|
writeJSON(w, 400, map[string]string{"error": "invalid pagination"})
|
|
return
|
|
}
|
|
reader, ok := config.Store.(sourceAuditReader)
|
|
if !ok {
|
|
writeJSON(w, 501, map[string]string{"error": "audit not configured"})
|
|
return
|
|
}
|
|
page, err := reader.ListSourceAudit(r.Context(), limit, offset)
|
|
if err != nil {
|
|
writeJSON(w, 500, map[string]string{"error": "无法读取数据源操作记录"})
|
|
return
|
|
}
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
writeJSON(w, 200, map[string]any{"data": page})
|
|
}
|