summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-15 17:54:43 -0600
committermo khan <mo@mokhan.ca>2025-04-15 17:54:43 -0600
commitb7ff80b7be532f4bb64c1daf8cef3462f9938362 (patch)
tree3d88661d72339be3fc81425b6d4397bcc8e8c603 /app
parent655fb6c4cc180dfcbc13c1b85e0fbf47019caec0 (diff)
feat: connect a blank dashboard controller
Diffstat (limited to 'app')
-rw-r--r--app/app.go6
-rw-r--r--app/controllers/dashboard/controller.go18
-rw-r--r--app/controllers/dashboard/controller_test.go29
-rw-r--r--app/init.go4
4 files changed, 55 insertions, 2 deletions
diff --git a/app/app.go b/app/app.go
index ad33d97..6fd3e7f 100644
--- a/app/app.go
+++ b/app/app.go
@@ -4,6 +4,7 @@ import (
"net/http"
"github.com/xlgmokha/x/pkg/ioc"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/dashboard"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/health"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/sessions"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/sparkles"
@@ -14,9 +15,10 @@ func New() http.Handler {
mux := ioc.MustResolve[*http.ServeMux](ioc.Default)
mountable := []web.Mountable{
- ioc.MustResolve[*sparkles.Controller](ioc.Default),
- ioc.MustResolve[*sessions.Controller](ioc.Default),
+ ioc.MustResolve[*dashboard.Controller](ioc.Default),
ioc.MustResolve[*health.Controller](ioc.Default),
+ ioc.MustResolve[*sessions.Controller](ioc.Default),
+ ioc.MustResolve[*sparkles.Controller](ioc.Default),
}
for _, m := range mountable {
m.MountTo(mux)
diff --git a/app/controllers/dashboard/controller.go b/app/controllers/dashboard/controller.go
new file mode 100644
index 0000000..060dbfa
--- /dev/null
+++ b/app/controllers/dashboard/controller.go
@@ -0,0 +1,18 @@
+package dashboard
+
+import "net/http"
+
+type Controller struct {
+}
+
+func New() *Controller {
+ return &Controller{}
+}
+
+func (c *Controller) MountTo(mux *http.ServeMux) {
+ mux.HandleFunc("GET /dashboard", c.Show)
+}
+
+func (c *Controller) Show(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "/", http.StatusFound)
+}
diff --git a/app/controllers/dashboard/controller_test.go b/app/controllers/dashboard/controller_test.go
new file mode 100644
index 0000000..0bfb3d6
--- /dev/null
+++ b/app/controllers/dashboard/controller_test.go
@@ -0,0 +1,29 @@
+package dashboard
+
+import (
+ "net/http"
+ "testing"
+
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test"
+ "gotest.tools/v3/assert"
+)
+
+func TestController(t *testing.T) {
+ mux := http.NewServeMux()
+ controller := New()
+ controller.MountTo(mux)
+
+ t.Run("GET /dashboard", func(t *testing.T) {
+ t.Run("when unauthenticated", func(t *testing.T) {
+ t.Run("redirects to the home page", func(t *testing.T) {
+ r, w := test.RequestResponse("GET", "/dashboard")
+
+ mux.ServeHTTP(w, r)
+
+ assert.Equal(t, http.StatusFound, w.Code)
+ location := w.HeaderMap.Get("Location")
+ assert.Equal(t, "/", location)
+ })
+ })
+ })
+}
diff --git a/app/init.go b/app/init.go
index f35c2d6..8ef0602 100644
--- a/app/init.go
+++ b/app/init.go
@@ -8,6 +8,7 @@ import (
"github.com/xlgmokha/x/pkg/env"
"github.com/xlgmokha/x/pkg/ioc"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/dashboard"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/health"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/sessions"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/sparkles"
@@ -34,6 +35,9 @@ func init() {
ioc.RegisterSingleton[*http.ServeMux](ioc.Default, func() *http.ServeMux {
return http.NewServeMux()
})
+ ioc.Register[*dashboard.Controller](ioc.Default, func() *dashboard.Controller {
+ return dashboard.New()
+ })
ioc.Register[*sparkles.Controller](ioc.Default, func() *sparkles.Controller {
return sparkles.New(ioc.MustResolve[db.Repository](ioc.Default))
})