fix(events): the events API returns a JSON view, not the row struct (#1980)

This commit is contained in:
sam committed 2026-11-15 18:07:28 +11:00
1 parent b89d9e0f05
commit e898acedc8
1 file changed
+30 -1
+30 -1
View File
@@ -259,7 +259,36 @@ func (m *Module) recent(w http.ResponseWriter, r *http.Request) {
httpjson.Error(w, http.StatusInternalServerError, err.Error())
return
}
httpjson.Write(w, http.StatusOK, events)
out := make([]eventView, 0, len(events))
for _, e := range events {
out = append(out, viewOf(e))
}
httpjson.Write(w, http.StatusOK, out)
}
// eventView is an event as the API returns it.
type eventView struct {
ID uuid.UUID `json:"id"`
Source string `json:"source"`
Type string `json:"type"`
Fields json.RawMessage `json:"fields"`
LinkedTo *uuid.UUID `json:"linked_to,omitempty"`
OccurredAt *time.Time `json:"occurred_at,omitempty"`
ReceivedAt time.Time `json:"received_at"`
Matched bool `json:"matched"`
DispatchedAt *time.Time `json:"dispatched_at,omitempty"`
}
func viewOf(e store.Event) eventView {
v := eventView{ID: e.ID, Source: e.Source, Type: e.Type, Fields: e.Fields, LinkedTo: e.LinkedTo,
ReceivedAt: e.ReceivedAt, Matched: e.Matched}
if e.OccurredAt.Valid {
v.OccurredAt = &e.OccurredAt.Time
}
if e.DispatchedAt.Valid {
v.DispatchedAt = &e.DispatchedAt.Time
}
return v
}
func newToken() (string, error) {