chore(deps): remove dependencies from handler package
This commit was merged in pull request #287.
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type HandlerAuth interface {
|
||||
handle(router *http.ServeMux)
|
||||
Handle(router *http.ServeMux)
|
||||
}
|
||||
|
||||
type HandlerAuthImpl struct {
|
||||
@@ -31,7 +31,7 @@ func NewHandlerAuth(db *sql.DB, service service.AuthService, serverSettings *typ
|
||||
}
|
||||
}
|
||||
|
||||
func (handler HandlerAuthImpl) handle(router *http.ServeMux) {
|
||||
func (handler HandlerAuthImpl) Handle(router *http.ServeMux) {
|
||||
// Don't use auth middleware for these routes, as it makes redirecting very difficult, if the mail is not yet verified
|
||||
router.Handle("/auth/signin", handler.handleSignInPage())
|
||||
router.Handle("/auth/signup", handler.handleSignUpPage())
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"me-fit/db"
|
||||
"me-fit/middleware"
|
||||
"me-fit/service"
|
||||
"me-fit/types"
|
||||
|
||||
"database/sql"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetHandler(d *sql.DB, serverSettings *types.ServerSettings) http.Handler {
|
||||
var router = http.NewServeMux()
|
||||
|
||||
authDb := db.NewAuthDbSqlite(d)
|
||||
workoutDb := db.NewWorkoutDbSqlite(d)
|
||||
|
||||
randomService := service.NewRandomServiceImpl()
|
||||
clockService := service.NewClockServiceImpl()
|
||||
mailService := service.NewMailServiceImpl(serverSettings)
|
||||
authService := service.NewAuthServiceImpl(authDb, randomService, clockService, mailService, serverSettings)
|
||||
workoutService := service.NewWorkoutServiceImpl(workoutDb, randomService, clockService, mailService, serverSettings)
|
||||
|
||||
indexHandler := NewIndexHandler(d, authService, serverSettings)
|
||||
authHandler := NewHandlerAuth(d, authService, serverSettings)
|
||||
workoutHandler := NewWorkoutHandler(d, workoutService, authService, serverSettings)
|
||||
|
||||
indexHandler.handle(router)
|
||||
|
||||
// Serve static files (CSS, JS and images)
|
||||
router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
|
||||
|
||||
workoutHandler.handle(router)
|
||||
|
||||
authHandler.handle(router)
|
||||
|
||||
return middleware.Wrapper(
|
||||
router,
|
||||
middleware.Log,
|
||||
middleware.ContentSecurityPolicy,
|
||||
middleware.Cors(serverSettings),
|
||||
middleware.Corp,
|
||||
middleware.Coop,
|
||||
)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type IndexHandler interface {
|
||||
handle(router *http.ServeMux)
|
||||
Handle(router *http.ServeMux)
|
||||
}
|
||||
|
||||
type IndexHandlerImpl struct {
|
||||
@@ -30,7 +30,7 @@ func NewIndexHandler(db *sql.DB, service service.AuthService, serverSettings *ty
|
||||
}
|
||||
}
|
||||
|
||||
func (handler IndexHandlerImpl) handle(router *http.ServeMux) {
|
||||
func (handler IndexHandlerImpl) Handle(router *http.ServeMux) {
|
||||
router.Handle("/", handler.handleIndexAnd404())
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type WorkoutHandler interface {
|
||||
handle(router *http.ServeMux)
|
||||
Handle(router *http.ServeMux)
|
||||
}
|
||||
|
||||
type WorkoutHandlerImpl struct {
|
||||
@@ -25,7 +25,7 @@ type WorkoutHandlerImpl struct {
|
||||
serverSettings *types.ServerSettings
|
||||
}
|
||||
|
||||
func NewWorkoutHandler(db *sql.DB, service service.WorkoutService, auth service.AuthService, serverSettings *types.ServerSettings) HandlerAuth {
|
||||
func NewWorkoutHandler(db *sql.DB, service service.WorkoutService, auth service.AuthService, serverSettings *types.ServerSettings) WorkoutHandler {
|
||||
return WorkoutHandlerImpl{
|
||||
db: db,
|
||||
service: service,
|
||||
@@ -34,7 +34,7 @@ func NewWorkoutHandler(db *sql.DB, service service.WorkoutService, auth service.
|
||||
}
|
||||
}
|
||||
|
||||
func (handler WorkoutHandlerImpl) handle(router *http.ServeMux) {
|
||||
func (handler WorkoutHandlerImpl) Handle(router *http.ServeMux) {
|
||||
router.Handle("/workout", handler.handleWorkoutPage())
|
||||
router.Handle("POST /api/workout", handler.handleAddWorkout())
|
||||
router.Handle("GET /api/workout", handler.handleGetWorkout())
|
||||
|
||||
Reference in New Issue
Block a user