Files
story/internal/httpapi/event_history.go
T

24 lines
685 B
Go
Raw Normal View History

package httpapi
import (
"data-terminal-cloud/internal/webevents"
"net/http"
"time"
)
func WebEventHistoryHandler(service *webevents.Service) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
principal, ok := webPrincipal(w, r)
if !ok {
return
}
items, err := service.History(r.Context(), principal, time.Now().Add(-7*24*time.Hour), 200)
if err != nil {
WriteError(w, r, http.StatusInternalServerError, "INTERNAL_ERROR", "近期动态读取失败,请重试")
return
}
w.Header().Set("Cache-Control", "no-store")
WriteJSON(w, r, http.StatusOK, map[string]any{"items": items, "limit": 200, "retention_days": 7})
})
}