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