Files
Kiro/internal/handlers/dashboard_handler.go

59 lines
1.5 KiB
Go

package handlers
import (
"html/template"
"log"
"net/http"
"path/filepath"
"custom-start-page/internal/middleware"
)
// DashboardHandler handles dashboard-related HTTP requests
type DashboardHandler struct {
templates *template.Template
}
// NewDashboardHandler creates a new dashboard handler
func NewDashboardHandler() *DashboardHandler {
// Parse templates
templates := template.Must(template.ParseGlob(filepath.Join("templates", "*.html")))
template.Must(templates.ParseGlob(filepath.Join("templates", "layouts", "*.html")))
return &DashboardHandler{
templates: templates,
}
}
// HandleDashboard displays the dashboard page
// GET /dashboard
func (h *DashboardHandler) HandleDashboard(w http.ResponseWriter, r *http.Request) {
// Get user ID from context (set by auth middleware)
userID, ok := middleware.GetUserIDFromContext(r.Context())
if !ok {
http.Error(w, "User ID not found in context", http.StatusInternalServerError)
return
}
// TODO: Fetch user's pages from database
// For now, we'll use mock data
pages := []map[string]interface{}{
{
"ID": "default-page",
"Name": "Home",
"Active": true,
},
}
// Render dashboard template
data := map[string]interface{}{
"UserID": userID,
"Pages": pages,
}
if err := h.templates.ExecuteTemplate(w, "dashboard.html", data); err != nil {
log.Printf("Failed to render dashboard template: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
}