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
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package handler
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"code.cubecraftcreations.com/CubeCraft-Creations/Control-Center/go-backend/internal/models"
|
|
)
|
|
|
|
// ─── Task Handlers ─────────────────────────────────────────────────────────────
|
|
|
|
// ListTasks handles GET /api/tasks.
|
|
func (h *Handler) ListTasks(w http.ResponseWriter, r *http.Request) {
|
|
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{}
|
|
}
|
|
|
|
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: totalCount,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
HasMore: end < len(tasks),
|
|
})
|
|
}
|