Skip to content

Commit a153afa

Browse files
committed
refactor: some refactoring
1 parent 996008e commit a153afa

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

infrastructure/setup/app.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ func (app *App) MapRoutes() {
6868

6969
var authRequired = createJwtAuthRequiredMiddleware(&jwtService)
7070

71-
app.handleFunc("GET /", notFound.GetHandler)
72-
app.handleFunc("POST /", notFound.GetHandler)
71+
app.handleFunc("GET /", notFound.Show404)
72+
app.handleFunc("POST /", notFound.Show404)
7373

7474
var forgotPasswordController = forgotPassword.NewController(app.Db)
7575

76-
app.handleFunc("GET /forgot-password", forgotPasswordController.GetHandler)
77-
app.handleFunc("POST /forgot-password", forgotPasswordController.PostHandler)
78-
app.handleFunc("POST /set-password", forgotPasswordController.PostSetPasswordHandler)
76+
app.handleFunc("GET /forgot-password", forgotPasswordController.GetForgotPasswordForm)
77+
app.handleFunc("POST /forgot-password", forgotPasswordController.SubmitForgotPasswordForm)
78+
app.handleFunc("POST /set-password", forgotPasswordController.SetPassword)
7979

8080
var indexController = index.NewController(app.Config)
8181
app.handleFunc("GET /{$}", authRequired(indexController.GetHandler))

pages/forgotPassword/controller.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package forgotPassword
2+
3+
import "gorm.io/gorm"
4+
5+
type Controller struct {
6+
db *gorm.DB
7+
}
8+
9+
func NewController(db *gorm.DB) *Controller {
10+
return &Controller{db: db}
11+
}

pages/forgotPassword/forgotPassword.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"go-api/infrastructure/myLog"
88
"go-api/infrastructure/reqRes"
99
"go-api/pages"
10-
"gorm.io/gorm"
1110
"html/template"
1211
"net/http"
12+
13+
"gorm.io/gorm"
1314
)
1415

1516
var forgotPasswordTemplate = template.Must(
@@ -33,15 +34,7 @@ type ResetPasswordPageData struct {
3334
MinLength int
3435
}
3536

36-
type Controller struct {
37-
db *gorm.DB
38-
}
39-
40-
func NewController(db *gorm.DB) *Controller {
41-
return &Controller{db: db}
42-
}
43-
44-
func (controller *Controller) GetHandler(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
37+
func (controller *Controller) GetForgotPasswordForm(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
4538
renderForgotPasswordPage(w, r, "")
4639
}
4740

@@ -58,7 +51,7 @@ func renderForgotPasswordPage(w reqRes.MyResponseWriter, r *reqRes.MyRequest, er
5851
w.RenderTemplate(forgotPasswordTemplate, pageData)
5952
}
6053

61-
func (controller *Controller) PostHandler(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
54+
func (controller *Controller) SubmitForgotPasswordForm(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
6255
ok := r.ParseFormRequired(w)
6356
if !ok {
6457
return
@@ -106,7 +99,7 @@ func renderResetPasswordForm(w reqRes.MyResponseWriter, r *reqRes.MyRequest, use
10699
w.RenderTemplate(resetPasswordFormTemplate, pageData)
107100
}
108101

109-
func (controller *Controller) PostSetPasswordHandler(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
102+
func (controller *Controller) SetPassword(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
110103
ok := r.ParseFormRequired(w)
111104
if !ok {
112105
return

pages/login/loginController.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
"go-api/infrastructure/myLog"
1010
"go-api/infrastructure/reqRes"
1111
"go-api/pages"
12-
"gorm.io/gorm"
1312
"html/template"
1413
"net/http"
1514
"strings"
15+
16+
"gorm.io/gorm"
1617
)
1718

1819
var loginTemplate = template.Must(template.ParseFiles("pages/base.gohtml", "pages/login/login.gohtml"))

pages/notFound/notFoundController.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
var notFoundTemplate = template.Must(template.ParseFiles("pages/base.gohtml", "pages/notFound/notFound.gohtml"))
1010

11-
func GetHandler(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
11+
func Show404(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
1212
pageData := pages.NewPageData(r, "404: page not found")
1313

1414
w.RenderTemplate(notFoundTemplate, pageData)

0 commit comments

Comments
 (0)