2025-06-10 21:09:58 +02:00
|
|
|
package quiz
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2025-06-13 16:55:46 +02:00
|
|
|
"time"
|
2025-06-10 21:09:58 +02:00
|
|
|
|
|
|
|
"forge.cadoles.com/wpetit/kouiz/internal/store"
|
2025-06-15 14:46:32 +02:00
|
|
|
"forge.cadoles.com/wpetit/kouiz/internal/timex"
|
2025-06-10 21:09:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Handler struct {
|
2025-06-13 16:55:46 +02:00
|
|
|
mux *http.ServeMux
|
|
|
|
store *store.Store
|
|
|
|
playInterval time.Duration
|
2025-06-15 14:46:32 +02:00
|
|
|
playPeriod timex.PeriodType
|
2025-06-15 16:44:44 +02:00
|
|
|
playDelay time.Duration
|
2025-06-10 21:09:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServeHTTP implements http.Handler.
|
|
|
|
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
h.mux.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
2025-06-15 16:44:44 +02:00
|
|
|
func NewHandler(store *store.Store, playInterval time.Duration, playPeriod timex.PeriodType, playDelay time.Duration) *Handler {
|
2025-06-10 21:09:58 +02:00
|
|
|
h := &Handler{
|
2025-06-13 16:55:46 +02:00
|
|
|
mux: http.NewServeMux(),
|
|
|
|
store: store,
|
|
|
|
playInterval: playInterval,
|
2025-06-15 14:46:32 +02:00
|
|
|
playPeriod: playPeriod,
|
2025-06-15 16:44:44 +02:00
|
|
|
playDelay: playDelay,
|
2025-06-10 21:09:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
h.mux.HandleFunc("GET /", h.getQuizPage)
|
2025-06-15 14:46:32 +02:00
|
|
|
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)
|
2025-06-10 21:09:58 +02:00
|
|
|
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ http.Handler = &Handler{}
|