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.1 KiB
Go
36 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"code.cubecraftcreations.com/CubeCraft-Creations/Control-Center/go-backend/internal/models"
|
|
)
|
|
|
|
// ─── Project Handlers ──────────────────────────────────────────────────────────
|
|
|
|
// ListProjects handles GET /api/projects.
|
|
func (h *Handler) ListProjects(w http.ResponseWriter, r *http.Request) {
|
|
projects, err := h.Projects.List(r.Context())
|
|
if err != nil {
|
|
slog.Error("list projects failed", "error", err)
|
|
writeJSON(w, http.StatusInternalServerError, models.ErrorResponse{Error: "failed to list projects"})
|
|
return
|
|
}
|
|
if projects == nil {
|
|
projects = []models.Project{}
|
|
}
|
|
|
|
page, pageSize := parsePagination(r)
|
|
start, end := paginateSlice(len(projects), page, pageSize)
|
|
|
|
totalCount, _ := h.Projects.Count(r.Context())
|
|
writeJSON(w, http.StatusOK, models.PaginatedResponse{
|
|
Data: projects[start:end],
|
|
TotalCount: totalCount,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
HasMore: end < len(projects),
|
|
})
|
|
}
|