CUB-127: implement Control Center CRUD API in Go
This commit is contained in:
28
go-backend/internal/handler/project.go
Normal file
28
go-backend/internal/handler/project.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"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 := h.ProjectStore.List()
|
||||
if projects == nil {
|
||||
projects = []models.Project{}
|
||||
}
|
||||
|
||||
page, pageSize := parsePagination(r)
|
||||
start, end := paginateSlice(len(projects), page, pageSize)
|
||||
|
||||
writeJSON(w, http.StatusOK, models.PaginatedResponse{
|
||||
Data: projects[start:end],
|
||||
TotalCount: h.ProjectStore.Count(),
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
HasMore: end < len(projects),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user