feat: setting up routes for spaces landing page

This commit is contained in:
juancwu 2026-04-07 12:38:07 +00:00
commit 7c375e1002
8 changed files with 94 additions and 12 deletions

View file

@ -14,14 +14,14 @@ func NewHomeHandler() *homeHandler {
return &homeHandler{}
}
// HomePage will redirect to /auth if not authenticated or to /app/dashboard if authenticated.
// HomePage will redirect to /auth if not authenticated or to /app/spaces if authenticated.
func (h *homeHandler) HomePage(w http.ResponseWriter, r *http.Request) {
user := ctxkeys.User(r.Context())
if user == nil {
http.Redirect(w, r, "/auth", http.StatusSeeOther)
return
}
http.Redirect(w, r, "/app/dashboard", http.StatusSeeOther)
http.Redirect(w, r, "/app/spaces", http.StatusSeeOther)
}
func (h *homeHandler) PrivacyPage(w http.ResponseWriter, r *http.Request) {

View file

@ -38,5 +38,5 @@ func TestHomeHandler_HomePage_Authenticated(t *testing.T) {
h.HomePage(w, req)
assert.Equal(t, http.StatusSeeOther, w.Code)
assert.Equal(t, "/app/dashboard", w.Header().Get("Location"))
assert.Equal(t, "/app/spaces", w.Header().Get("Location"))
}

View file

@ -0,0 +1,13 @@
package handler
import "net/http"
type redirectHandler struct{}
func NewRedirectHandler() *redirectHandler {
return &redirectHandler{}
}
func (h *redirectHandler) Spaces(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/app/spaces", http.StatusMovedPermanently)
}

View file

@ -0,0 +1,21 @@
package handler
import (
"net/http"
"net/http/httptest"
"testing"
"git.juancwu.dev/juancwu/budgit/internal/testutil"
"github.com/stretchr/testify/assert"
)
func TestRedirectHandler_RederictToSpaces(t *testing.T) {
h := NewRedirectHandler()
req := testutil.NewRequest(t, http.MethodPost, "/app/dashboard", nil)
w := httptest.NewRecorder()
h.Spaces(w, req)
assert.Equal(t, http.StatusMovedPermanently, w.Code)
assert.Equal(t, "/app/spaces", w.Header().Get("Location"))
}

21
internal/handler/space.go Normal file
View file

@ -0,0 +1,21 @@
package handler
import (
"net/http"
"git.juancwu.dev/juancwu/budgit/internal/service"
"git.juancwu.dev/juancwu/budgit/internal/ui"
"git.juancwu.dev/juancwu/budgit/internal/ui/pages"
)
type spaceHandler struct {
spaceService *service.SpaceService
}
func NewSpaceHandler(spaceService *service.SpaceService) *spaceHandler {
return &spaceHandler{spaceService: spaceService}
}
func (h *spaceHandler) SpacesPage(w http.ResponseWriter, r *http.Request) {
ui.Render(w, r, pages.Spaces())
}