fix: remove redundante names
This commit was merged in pull request #299.
This commit is contained in:
@@ -13,23 +13,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type HandlerAuth interface {
|
||||
type Auth interface {
|
||||
Handle(router *http.ServeMux)
|
||||
}
|
||||
|
||||
type HandlerAuthImpl struct {
|
||||
service service.AuthService
|
||||
type AuthImpl struct {
|
||||
service service.Auth
|
||||
render *Render
|
||||
}
|
||||
|
||||
func NewHandlerAuth(service service.AuthService, render *Render) HandlerAuth {
|
||||
return HandlerAuthImpl{
|
||||
func NewAuth(service service.Auth, render *Render) Auth {
|
||||
return AuthImpl{
|
||||
service: service,
|
||||
render: render,
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) Handle(router *http.ServeMux) {
|
||||
func (handler AuthImpl) Handle(router *http.ServeMux) {
|
||||
router.Handle("/auth/signin", handler.handleSignInPage())
|
||||
router.Handle("/api/auth/signin", handler.handleSignIn())
|
||||
|
||||
@@ -56,7 +56,7 @@ var (
|
||||
securityWaitDuration = 250 * time.Millisecond
|
||||
)
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignInPage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignInPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, _ := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if user != nil {
|
||||
@@ -74,7 +74,7 @@ func (handler HandlerAuthImpl) handleSignInPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignIn() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignIn() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := utils.WaitMinimumTime(securityWaitDuration, func() (*service.User, error) {
|
||||
var email = r.FormValue("email")
|
||||
@@ -119,7 +119,7 @@ func (handler HandlerAuthImpl) handleSignIn() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignUpPage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignUpPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, _ := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
|
||||
@@ -137,7 +137,7 @@ func (handler HandlerAuthImpl) handleSignUpPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, _ := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if user == nil {
|
||||
@@ -155,7 +155,7 @@ func (handler HandlerAuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleVerifyResendComp() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleVerifyResendComp() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
@@ -172,7 +172,7 @@ func (handler HandlerAuthImpl) handleVerifyResendComp() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignUpVerifyResponsePage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignUpVerifyResponsePage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
token := r.URL.Query().Get("token")
|
||||
@@ -187,7 +187,7 @@ func (handler HandlerAuthImpl) handleSignUpVerifyResponsePage() http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignUp() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignUp() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var email = r.FormValue("email")
|
||||
var password = r.FormValue("password")
|
||||
@@ -217,7 +217,7 @@ func (handler HandlerAuthImpl) handleSignUp() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleSignOut() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleSignOut() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
err := handler.service.SignOut(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
@@ -241,7 +241,7 @@ func (handler HandlerAuthImpl) handleSignOut() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleDeleteAccountPage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleDeleteAccountPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// An unverified email should be able to delete their account
|
||||
user, err := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
@@ -254,7 +254,7 @@ func (handler HandlerAuthImpl) handleDeleteAccountPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleDeleteAccountComp() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleDeleteAccountComp() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
@@ -280,7 +280,7 @@ func (handler HandlerAuthImpl) handleDeleteAccountComp() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleChangePasswordPage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleChangePasswordPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
isPasswordReset := r.URL.Query().Has("token")
|
||||
@@ -297,7 +297,7 @@ func (handler HandlerAuthImpl) handleChangePasswordPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleChangePasswordComp() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleChangePasswordComp() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
user, err := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
@@ -319,7 +319,7 @@ func (handler HandlerAuthImpl) handleChangePasswordComp() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleResetPasswordPage() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleResetPasswordPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
user, err := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
@@ -333,7 +333,7 @@ func (handler HandlerAuthImpl) handleResetPasswordPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleForgotPasswordComp() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleForgotPasswordComp() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
email := r.FormValue("email")
|
||||
@@ -351,7 +351,7 @@ func (handler HandlerAuthImpl) handleForgotPasswordComp() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handleForgotPasswordResponseComp() http.HandlerFunc {
|
||||
func (handler AuthImpl) handleForgotPasswordResponseComp() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
pageUrl, err := url.Parse(r.Header.Get("HX-Current-URL"))
|
||||
|
||||
@@ -10,27 +10,27 @@ import (
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
type IndexHandler interface {
|
||||
type Index interface {
|
||||
Handle(router *http.ServeMux)
|
||||
}
|
||||
|
||||
type IndexHandlerImpl struct {
|
||||
service service.AuthService
|
||||
type IndexImpl struct {
|
||||
service service.Auth
|
||||
render *Render
|
||||
}
|
||||
|
||||
func NewIndexHandler(service service.AuthService, render *Render) IndexHandler {
|
||||
return IndexHandlerImpl{
|
||||
func NewIndex(service service.Auth, render *Render) Index {
|
||||
return IndexImpl{
|
||||
service: service,
|
||||
render: render,
|
||||
}
|
||||
}
|
||||
|
||||
func (handler IndexHandlerImpl) Handle(router *http.ServeMux) {
|
||||
func (handler IndexImpl) Handle(router *http.ServeMux) {
|
||||
router.Handle("/", handler.handleIndexAnd404())
|
||||
}
|
||||
|
||||
func (handler IndexHandlerImpl) handleIndexAnd404() http.HandlerFunc {
|
||||
func (handler IndexImpl) handleIndexAnd404() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, _ := handler.service.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Cors(serverSettings *types.ServerSettings) func(http.Handler) http.Handler {
|
||||
func Cors(serverSettings *types.Settings) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", serverSettings.BaseUrl)
|
||||
|
||||
@@ -13,12 +13,12 @@ import (
|
||||
)
|
||||
|
||||
type Render struct {
|
||||
serverSettings *types.ServerSettings
|
||||
settings *types.Settings
|
||||
}
|
||||
|
||||
func NewRender(serverSettings *types.ServerSettings) *Render {
|
||||
func NewRender(settings *types.Settings) *Render {
|
||||
return &Render{
|
||||
serverSettings: serverSettings,
|
||||
settings: settings,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (render *Render) Render(r *http.Request, w http.ResponseWriter, comp templ.
|
||||
|
||||
func (render *Render) RenderLayout(r *http.Request, w http.ResponseWriter, slot templ.Component, user *service.User) {
|
||||
userComp := render.getUserComp(user)
|
||||
layout := template.Layout(slot, userComp, render.serverSettings.Environment)
|
||||
layout := template.Layout(slot, userComp, render.settings.Environment)
|
||||
|
||||
render.Render(r, w, layout)
|
||||
}
|
||||
|
||||
@@ -11,32 +11,32 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type WorkoutHandler interface {
|
||||
type Workout interface {
|
||||
Handle(router *http.ServeMux)
|
||||
}
|
||||
|
||||
type WorkoutHandlerImpl struct {
|
||||
service service.WorkoutService
|
||||
auth service.AuthService
|
||||
type WorkoutImpl struct {
|
||||
service service.Workout
|
||||
auth service.Auth
|
||||
render *Render
|
||||
}
|
||||
|
||||
func NewWorkoutHandler(service service.WorkoutService, auth service.AuthService, render *Render) WorkoutHandler {
|
||||
return WorkoutHandlerImpl{
|
||||
func NewWorkout(service service.Workout, auth service.Auth, render *Render) Workout {
|
||||
return WorkoutImpl{
|
||||
service: service,
|
||||
auth: auth,
|
||||
render: render,
|
||||
}
|
||||
}
|
||||
|
||||
func (handler WorkoutHandlerImpl) Handle(router *http.ServeMux) {
|
||||
func (handler WorkoutImpl) Handle(router *http.ServeMux) {
|
||||
router.Handle("/workout", handler.handleWorkoutPage())
|
||||
router.Handle("POST /api/workout", handler.handleAddWorkout())
|
||||
router.Handle("GET /api/workout", handler.handleGetWorkout())
|
||||
router.Handle("DELETE /api/workout/{id}", handler.handleDeleteWorkout())
|
||||
}
|
||||
|
||||
func (handler WorkoutHandlerImpl) handleWorkoutPage() http.HandlerFunc {
|
||||
func (handler WorkoutImpl) handleWorkoutPage() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := handler.auth.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
@@ -50,7 +50,7 @@ func (handler WorkoutHandlerImpl) handleWorkoutPage() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler WorkoutHandlerImpl) handleAddWorkout() http.HandlerFunc {
|
||||
func (handler WorkoutImpl) handleAddWorkout() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := handler.auth.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
@@ -77,7 +77,7 @@ func (handler WorkoutHandlerImpl) handleAddWorkout() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler WorkoutHandlerImpl) handleGetWorkout() http.HandlerFunc {
|
||||
func (handler WorkoutImpl) handleGetWorkout() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := handler.auth.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
@@ -100,7 +100,7 @@ func (handler WorkoutHandlerImpl) handleGetWorkout() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (handler WorkoutHandlerImpl) handleDeleteWorkout() http.HandlerFunc {
|
||||
func (handler WorkoutImpl) handleDeleteWorkout() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := handler.auth.GetUserFromSessionId(utils.GetSessionID(r))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user