refactor: move code so it's a little more organized

This commit is contained in:
Mark Bailey 2024-11-26 08:52:58 -05:00
parent 15abbde592
commit 19991e2947

View File

@ -16,31 +16,6 @@ import (
"git.markbailey.dev/cerbervs/ptpp/view/user" "git.markbailey.dev/cerbervs/ptpp/view/user"
) )
type SignUpHandler struct {
controller.Controller
}
func (c SignUpHandler) Init(s session.IManager, d database.IDB, l logger.ILogger, ctx controller.IControllerCtx) controller.IController {
c.Logger = l
c.Db = d
c.Session = s
c.Ctx = ctx
return c
}
type SignInHandler struct {
controller.Controller
}
func (c SignInHandler) Init(s session.IManager, d database.IDB, l logger.ILogger, ctx controller.IControllerCtx) controller.IController {
c.Logger = l
c.Db = d
c.Session = s
return c
}
type PopulateHandler struct { type PopulateHandler struct {
controller.Controller controller.Controller
} }
@ -54,19 +29,6 @@ func (c PopulateHandler) Init(s session.IManager, d database.IDB, l logger.ILogg
return c return c
} }
type SignOutHandler struct {
controller.Controller
}
func (c SignOutHandler) Init(s session.IManager, d database.IDB, l logger.ILogger, ctx controller.IControllerCtx) controller.IController {
c.Logger = l
c.Db = d
c.Session = s
c.Ctx = ctx
return c
}
func (c PopulateHandler) Get(w http.ResponseWriter, r *http.Request) error { func (c PopulateHandler) Get(w http.ResponseWriter, r *http.Request) error {
existingOrg, err := c.Db.Repo().FindOrganizationByName("CerbervsSoft") existingOrg, err := c.Db.Repo().FindOrganizationByName("CerbervsSoft")
if existingOrg != nil && err == nil { if existingOrg != nil && err == nil {
@ -96,6 +58,18 @@ func (c PopulateHandler) Get(w http.ResponseWriter, r *http.Request) error {
return util.Redirect(w, r, c.Ctx.GetRouteByName("app.user.sign_up"), http.StatusSeeOther, false) return util.Redirect(w, r, c.Ctx.GetRouteByName("app.user.sign_up"), http.StatusSeeOther, false)
} }
type SignInHandler struct {
controller.Controller
}
func (c SignInHandler) Init(s session.IManager, d database.IDB, l logger.ILogger, ctx controller.IControllerCtx) controller.IController {
c.Logger = l
c.Db = d
c.Session = s
return c
}
type UserSignInForm struct { type UserSignInForm struct {
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
@ -214,6 +188,19 @@ func (c SignInHandler) Post(w http.ResponseWriter, r *http.Request) error {
} }
} }
type SignUpHandler struct {
controller.Controller
}
func (c SignUpHandler) Init(s session.IManager, d database.IDB, l logger.ILogger, ctx controller.IControllerCtx) controller.IController {
c.Logger = l
c.Db = d
c.Session = s
c.Ctx = ctx
return c
}
type UserSignUpForm struct { type UserSignUpForm struct {
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
@ -328,6 +315,19 @@ func (c SignUpHandler) Post(w http.ResponseWriter, r *http.Request) error {
return nil return nil
} }
type SignOutHandler struct {
controller.Controller
}
func (c SignOutHandler) Init(s session.IManager, d database.IDB, l logger.ILogger, ctx controller.IControllerCtx) controller.IController {
c.Logger = l
c.Db = d
c.Session = s
c.Ctx = ctx
return c
}
func (c SignOutHandler) Get(w http.ResponseWriter, r *http.Request) error { func (c SignOutHandler) Get(w http.ResponseWriter, r *http.Request) error {
sess := c.Session.SessionStart(w, r) sess := c.Session.SessionStart(w, r)