summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-05-08 11:07:55 -0600
committermo khan <mo@mokhan.ca>2025-05-08 11:07:55 -0600
commitf5fd5ef8edc832f86c4cbb752ba4d27959753d19 (patch)
tree11503c6901d2de7a0ef7b34008fb60c3b478fdc7 /app
parentd4758497b63644b2baaef2115984fe7ba14fff2a (diff)
refactor: move html render to data transfer object
Diffstat (limited to 'app')
-rw-r--r--app/controllers/sessions/controller.go9
-rw-r--r--app/controllers/sessions/dto.go14
2 files changed, 15 insertions, 8 deletions
diff --git a/app/controllers/sessions/controller.go b/app/controllers/sessions/controller.go
index d5b2ba6..afc44f7 100644
--- a/app/controllers/sessions/controller.go
+++ b/app/controllers/sessions/controller.go
@@ -7,7 +7,6 @@ import (
"github.com/xlgmokha/x/pkg/env"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/middleware"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/views"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web"
@@ -102,13 +101,7 @@ func (c *Controller) Destroy(w http.ResponseWriter, r *http.Request) {
func (c *Controller) redirectTo(w http.ResponseWriter, r *http.Request, location string) {
if env.Fetch("APP_ENV", "development") == "production" {
- w.WriteHeader(http.StatusOK)
- w.Header().Add("Content-Type", "text/html")
-
- if err := views.Render(w, "sessions/redirect", &RedirectDTO{URL: location}); err != nil {
- pls.LogError(r.Context(), err)
- w.WriteHeader(http.StatusInternalServerError)
- }
+ (&RedirectDTO{URL: location}).ServeHTTP(w, r)
} else {
http.Redirect(w, r, location, http.StatusFound)
}
diff --git a/app/controllers/sessions/dto.go b/app/controllers/sessions/dto.go
index 4bb959f..a3ce6ba 100644
--- a/app/controllers/sessions/dto.go
+++ b/app/controllers/sessions/dto.go
@@ -1,5 +1,19 @@
package sessions
+import (
+ "net/http"
+
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/views"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
+)
+
type RedirectDTO struct {
URL string
}
+
+func (d *RedirectDTO) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ w.Header().Add("Content-Type", "text/html")
+
+ pls.LogError(r.Context(), views.Render(w, "sessions/redirect", d))
+}