handles routes in routes

This commit is contained in:
Robin Olsen
2026-02-13 13:38:54 +01:00
parent 6f2c2ede9b
commit 54c0845f28
2 changed files with 0 additions and 65 deletions

View File

@@ -1,21 +0,0 @@
package handler
import (
"net/http"
"github.com/LazyBachelor/LazyPM/internal/service"
)
type Route struct {
Pattern string
Handler http.Handler
}
func GetRoutes(svc *service.Services) []Route {
var routes []Route
routes = append(routes, PagesRoutes(svc)...)
routes = append(routes, IssuesRoutes(svc)...)
return routes
}

View File

@@ -1,44 +0,0 @@
package handler
import (
"net/http"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/web/components"
"github.com/LazyBachelor/LazyPM/pkg/web/routes"
)
func PagesRoutes(svc *service.Services) []Route {
return []Route{
{Pattern: "/", Handler: IndexHandler(svc)},
}
}
func IndexHandler(svc *service.Services) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
handleNotFound(w, r)
return
}
issues, err := svc.Beads.AllIssues(r.Context())
if err != nil {
http.Error(w, "Failed to retrieve issues",
http.StatusInternalServerError)
return
}
props := routes.IndexProps{
IssueTable: components.IssueTableProps{
Issues: issues,
},
}
routes.Index(props).Render(r.Context(), w)
}
}
func handleNotFound(w http.ResponseWriter, _ *http.Request) {
http.Error(w, "Page not found", http.StatusNotFound)
}