Files
qv/cmd/web/routes.go

39 lines
1015 B
Go
Raw Normal View History

2024-12-27 18:03:46 +01:00
package main
import (
2025-01-13 11:26:18 +01:00
api "code.dlmw.ch/dlmw/qv/internal"
2024-12-31 15:29:19 +01:00
"code.dlmw.ch/dlmw/qv/internal/models"
2025-01-13 10:56:36 +01:00
"code.dlmw.ch/dlmw/qv/ui"
2024-12-27 18:03:46 +01:00
"github.com/justinas/alice"
2024-12-31 15:29:19 +01:00
"log/slog"
2024-12-27 18:03:46 +01:00
"net/http"
)
2024-12-31 15:29:19 +01:00
type application struct {
logger *slog.Logger
elections models.ElectionModelInterface
voters models.VoterModelInterface
2025-01-08 13:57:49 +01:00
votes models.VoteModelInterface
2024-12-31 15:29:19 +01:00
}
2024-12-27 18:03:46 +01:00
func (app *application) routes() http.Handler {
mux := http.NewServeMux()
2025-01-14 13:43:16 +01:00
cached := alice.New(app.cacheStatic)
mux.Handle("GET /static/", cached.Then(http.FileServerFS(ui.Files)))
mux.HandleFunc("GET /", app.indexPage)
2025-01-13 10:56:36 +01:00
mux.HandleFunc("GET /election/create", app.createElectionPage)
2025-01-20 18:08:19 +01:00
mux.HandleFunc("GET /election/{id}/results", app.getElectionResultsPage)
2025-01-17 16:48:38 +01:00
mux.HandleFunc("GET /election/{id}", app.getElectionPage)
2025-01-13 10:56:36 +01:00
2025-01-13 11:26:18 +01:00
api.HandlerWithOptions(app, api.StdHTTPServerOptions{
BaseRouter: mux,
2025-01-14 12:40:30 +01:00
BaseURL: "/api",
2025-01-13 11:26:18 +01:00
ErrorHandlerFunc: app.badRequestError,
})
2024-12-27 18:03:46 +01:00
standard := alice.New(app.recoverPanic, app.logRequest)
return standard.Then(mux)
}