CUB-127: implement Control Center CRUD API in Go
This commit is contained in:
28
go-backend/internal/handler/session.go
Normal file
28
go-backend/internal/handler/session.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.cubecraftcreations.com/CubeCraft-Creations/Control-Center/go-backend/internal/models"
|
||||
)
|
||||
|
||||
// ─── Session Handlers ──────────────────────────────────────────────────────────
|
||||
|
||||
// ListSessions handles GET /api/sessions.
|
||||
func (h *Handler) ListSessions(w http.ResponseWriter, r *http.Request) {
|
||||
sessions := h.SessionStore.ListActive()
|
||||
if sessions == nil {
|
||||
sessions = []models.Session{}
|
||||
}
|
||||
|
||||
page, pageSize := parsePagination(r)
|
||||
start, end := paginateSlice(len(sessions), page, pageSize)
|
||||
|
||||
writeJSON(w, http.StatusOK, models.PaginatedResponse{
|
||||
Data: sessions[start:end],
|
||||
TotalCount: h.SessionStore.Count(),
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
HasMore: end < len(sessions),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user