Files
Agent-System/internal/server/notification_handlers.go
T
weichenandCursor 4bfe1cb5ad feat(api): wire document approval hook and project notifications API.
Register workflow approval callback on server start and expose GET /projects/{id}/notifications.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 02:50:23 +00:00

36 lines
954 B
Go

package server
import (
"net/http"
"strconv"
)
func (s *Server) handleListProjectNotifications(w http.ResponseWriter, r *http.Request) {
user, ok := s.requireAuthenticatedUser(w, r)
if !ok {
return
}
if s.notifySvc == nil || !s.notifySvc.Available() {
http.Error(w, "notification service unavailable", http.StatusServiceUnavailable)
return
}
projectID, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil || projectID <= 0 {
http.Error(w, "invalid project id", http.StatusBadRequest)
return
}
sinceID, _ := strconv.ParseInt(r.URL.Query().Get("since_id"), 10, 64)
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
items, err := s.notifySvc.ListProjectNotifications(r.Context(), user.ID, projectID, sinceID, limit)
if err != nil {
http.Error(w, "list notifications failed: "+err.Error(), http.StatusInternalServerError)
return
}
writeJSONResponse(w, http.StatusOK, map[string]any{
"items": items,
})
}