fix: refactor code to be testable #181
This commit was merged in pull request #212.
This commit is contained in:
@@ -13,25 +13,27 @@ import (
|
||||
func GetHandler(d *sql.DB, serverSettings *types.ServerSettings) http.Handler {
|
||||
var router = http.NewServeMux()
|
||||
|
||||
router.HandleFunc("/", service.HandleIndexAnd404(d, serverSettings))
|
||||
authDb := db.NewAuthDbSqlite(d)
|
||||
workoutDb := db.NewWorkoutDbSqlite(d)
|
||||
|
||||
randomGenerator := service.NewRandomGeneratorImpl()
|
||||
clock := service.NewClockImpl()
|
||||
dbAuth := db.NewDbAuthSqlite(d)
|
||||
randomService := service.NewRandomServiceImpl()
|
||||
clockService := service.NewClockServiceImpl()
|
||||
mailService := service.NewMailServiceImpl(serverSettings)
|
||||
serviceAuth := service.NewServiceAuthImpl(dbAuth, randomGenerator, clock, mailService, serverSettings)
|
||||
handlerAuth := NewHandlerAuth(d, serviceAuth, 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/"))))
|
||||
|
||||
handleWorkout(d, router, serverSettings)
|
||||
workoutHandler.handle(router)
|
||||
|
||||
handlerAuth.handle(router)
|
||||
authHandler.handle(router)
|
||||
|
||||
return middleware.Logging(middleware.EnableCors(serverSettings, router))
|
||||
}
|
||||
|
||||
func authMiddleware(db *sql.DB, h http.Handler) http.Handler {
|
||||
return middleware.EnsureValidSession(db, h)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user