Files
kouiz/internal/http/handler/webui/quiz/handler.go
2025-06-18 19:12:16 +02:00

46 lines
1.2 KiB
Go

package quiz
import (
"net/http"
"time"
"forge.cadoles.com/wpetit/kouiz/internal/store"
"forge.cadoles.com/wpetit/kouiz/internal/timex"
)
type Handler struct {
mux *http.ServeMux
store *store.Store
playInterval time.Duration
playPeriod timex.PeriodType
playDelay time.Duration
offDays []time.Weekday
}
// ServeHTTP implements http.Handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.mux.ServeHTTP(w, r)
}
func NewHandler(store *store.Store, playInterval time.Duration, playPeriod timex.PeriodType, playDelay time.Duration, offDays []time.Weekday) *Handler {
h := &Handler{
mux: http.NewServeMux(),
store: store,
playInterval: playInterval,
playPeriod: playPeriod,
playDelay: playDelay,
offDays: offDays,
}
h.mux.HandleFunc("GET /", h.getQuizPage)
h.mux.HandleFunc("GET /leaderboard", h.getLeadeboardPage)
h.mux.HandleFunc("POST /select", h.handleSelectEntryForm)
h.mux.HandleFunc("POST /answer", h.handleAnswerForm)
h.mux.HandleFunc("GET /result", h.getResultPage)
h.mux.HandleFunc("GET /history", h.getHistoryPage)
return h
}
var _ http.Handler = &Handler{}