fix: restructure handler yet again #181
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2024-09-18 21:28:44 +02:00
parent f184e261ee
commit ab3b255b92
3 changed files with 3 additions and 17 deletions

View File

@@ -1,7 +1,6 @@
package handler package handler
import ( import (
"log/slog"
"me-fit/service" "me-fit/service"
"database/sql" "database/sql"
@@ -9,7 +8,6 @@ import (
) )
func authUi(db *sql.DB) http.Handler { func authUi(db *sql.DB) http.Handler {
router := http.NewServeMux() router := http.NewServeMux()
router.Handle("/auth/signin", service.HandleSignInPage(db)) router.Handle("/auth/signin", service.HandleSignInPage(db))
@@ -21,15 +19,10 @@ func authUi(db *sql.DB) http.Handler {
router.Handle("/auth/reset-password", service.HandleResetPasswordPage(db)) router.Handle("/auth/reset-password", service.HandleResetPasswordPage(db))
router.Handle("/", service.HandleIndexAnd404(db)) router.Handle("/", service.HandleIndexAnd404(db))
// return router return router
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
slog.Warn(r.URL.Path)
router.ServeHTTP(w, r)
})
} }
func authApi(db *sql.DB) http.Handler { func authApi(db *sql.DB) http.Handler {
router := http.NewServeMux() router := http.NewServeMux()
router.Handle("/api/auth/signup", service.HandleSignUpComp(db)) router.Handle("/api/auth/signup", service.HandleSignUpComp(db))

View File

@@ -21,6 +21,7 @@ func GetHandler(db *sql.DB) http.Handler {
router.Handle("/workout", auth(db, workoutUi(db))) router.Handle("/workout", auth(db, workoutUi(db)))
router.Handle("/api/workout", auth(db, workoutApi(db))) router.Handle("/api/workout", auth(db, workoutApi(db)))
// Needed a second time with trailing slash, otherwise either /api/workout or /api/workout/{id} does not match
router.Handle("/api/workout/", auth(db, workoutApi(db))) router.Handle("/api/workout/", auth(db, workoutApi(db)))
return middleware.Logging( return middleware.Logging(

View File

@@ -1,7 +1,6 @@
package handler package handler
import ( import (
"log/slog"
"me-fit/service" "me-fit/service"
"database/sql" "database/sql"
@@ -9,11 +8,9 @@ import (
) )
func workoutUi(db *sql.DB) http.Handler { func workoutUi(db *sql.DB) http.Handler {
router := http.NewServeMux() router := http.NewServeMux()
router.Handle("/workout", service.HandleWorkoutPage(db)) router.Handle("/workout", service.HandleWorkoutPage(db))
router.Handle("/", service.HandleIndexAnd404(db))
return router return router
} }
@@ -21,14 +18,9 @@ func workoutUi(db *sql.DB) http.Handler {
func workoutApi(db *sql.DB) http.Handler { func workoutApi(db *sql.DB) http.Handler {
router := http.NewServeMux() router := http.NewServeMux()
// root = "/api/workout/"
router.Handle("POST /api/workout", service.HandleWorkoutNewComp(db)) router.Handle("POST /api/workout", service.HandleWorkoutNewComp(db))
router.Handle("GET /api/workout", service.HandleWorkoutGetComp(db)) router.Handle("GET /api/workout", service.HandleWorkoutGetComp(db))
router.Handle("DELETE /api/workout/{id}", service.HandleWorkoutDeleteComp(db)) router.Handle("DELETE /api/workout/{id}", service.HandleWorkoutDeleteComp(db))
// return router return router
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
slog.Warn(r.URL.Path)
router.ServeHTTP(w, r)
})
} }