CUB-123: integrate gateway, wire PostgreSQL repositories, add SSE streaming
All checks were successful
Dev Build / build-test (pull_request) Successful in 2m23s
All checks were successful
Dev Build / build-test (pull_request) Successful in 2m23s
- Create repository/ package with pgx-backed CRUD for agents, sessions, tasks, projects - Define AgentRepo/SessionRepo/TaskRepo/ProjectRepo interfaces - Update handler to use repository interfaces instead of in-memory stores - Add SSE broker with GET /api/events endpoint (text/event-stream) - Add gateway client that polls OpenClaw for agent states - Add GATEWAY_URL and GATEWAY_POLL_INTERVAL config fields - Seed 5 demo agents (Otto, Rex, Dex, Hex, Pip) on empty DB - Update router to wire SSE broker - All 21 handler tests pass with mock repos
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"code.cubecraftcreations.com/CubeCraft-Creations/Control-Center/go-backend/internal/models"
|
||||
@@ -10,7 +11,12 @@ import (
|
||||
|
||||
// ListSessions handles GET /api/sessions.
|
||||
func (h *Handler) ListSessions(w http.ResponseWriter, r *http.Request) {
|
||||
sessions := h.SessionStore.ListActive()
|
||||
sessions, err := h.Sessions.ListActive(r.Context())
|
||||
if err != nil {
|
||||
slog.Error("list sessions failed", "error", err)
|
||||
writeJSON(w, http.StatusInternalServerError, models.ErrorResponse{Error: "failed to list sessions"})
|
||||
return
|
||||
}
|
||||
if sessions == nil {
|
||||
sessions = []models.Session{}
|
||||
}
|
||||
@@ -18,9 +24,10 @@ func (h *Handler) ListSessions(w http.ResponseWriter, r *http.Request) {
|
||||
page, pageSize := parsePagination(r)
|
||||
start, end := paginateSlice(len(sessions), page, pageSize)
|
||||
|
||||
totalCount, _ := h.Sessions.Count(r.Context())
|
||||
writeJSON(w, http.StatusOK, models.PaginatedResponse{
|
||||
Data: sessions[start:end],
|
||||
TotalCount: h.SessionStore.Count(),
|
||||
TotalCount: totalCount,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
HasMore: end < len(sessions),
|
||||
|
||||
Reference in New Issue
Block a user