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 (
|
||||
|
||||
// ListTasks handles GET /api/tasks.
|
||||
func (h *Handler) ListTasks(w http.ResponseWriter, r *http.Request) {
|
||||
tasks := h.TaskStore.ListRecent()
|
||||
tasks, err := h.Tasks.ListRecent(r.Context())
|
||||
if err != nil {
|
||||
slog.Error("list tasks failed", "error", err)
|
||||
writeJSON(w, http.StatusInternalServerError, models.ErrorResponse{Error: "failed to list tasks"})
|
||||
return
|
||||
}
|
||||
if tasks == nil {
|
||||
tasks = []models.Task{}
|
||||
}
|
||||
@@ -18,9 +24,10 @@ func (h *Handler) ListTasks(w http.ResponseWriter, r *http.Request) {
|
||||
page, pageSize := parsePagination(r)
|
||||
start, end := paginateSlice(len(tasks), page, pageSize)
|
||||
|
||||
totalCount, _ := h.Tasks.Count(r.Context())
|
||||
writeJSON(w, http.StatusOK, models.PaginatedResponse{
|
||||
Data: tasks[start:end],
|
||||
TotalCount: h.TaskStore.Count(),
|
||||
TotalCount: totalCount,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
HasMore: end < len(tasks),
|
||||
|
||||
Reference in New Issue
Block a user