fix: move implementation to "internal" package
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m49s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m8s

This commit was merged in pull request #138.
This commit is contained in:
2025-05-29 13:23:13 +02:00
parent 9bb0cc475d
commit 6219741634
72 changed files with 245 additions and 230 deletions

View File

@@ -0,0 +1,57 @@
package handler
import (
"net/http"
"spend-sparrow/internal/handler/middleware"
"spend-sparrow/internal/template"
"github.com/a-h/templ"
)
type Index interface {
Handle(router *http.ServeMux)
}
type IndexImpl struct {
render *Render
}
func NewIndex(render *Render) Index {
return IndexImpl{
render: render,
}
}
func (handler IndexImpl) Handle(router *http.ServeMux) {
router.Handle("/", handler.handleRootAnd404())
router.Handle("/empty", handler.handleEmpty())
}
func (handler IndexImpl) handleRootAnd404() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user := middleware.GetUser(r)
var comp templ.Component
var status int
if r.URL.Path != "/" {
comp = template.NotFound()
status = http.StatusNotFound
} else {
if user != nil {
comp = template.Dashboard()
} else {
comp = template.Index()
}
status = http.StatusOK
}
handler.render.RenderLayoutWithStatus(r, w, comp, user, status)
}
}
func (handler IndexImpl) handleEmpty() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Return nothing
}
}