feat: initial commit

This commit is contained in:
2025-06-15 14:46:32 +02:00
parent 85f0bc1024
commit c50d1858f2
25 changed files with 2002 additions and 55 deletions

View File

@ -5,12 +5,14 @@ import (
"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
}
// ServeHTTP implements http.Handler.
@ -18,15 +20,19 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.mux.ServeHTTP(w, r)
}
func NewHandler(store *store.Store, playInterval time.Duration) *Handler {
func NewHandler(store *store.Store, playInterval time.Duration, playPeriod timex.PeriodType) *Handler {
h := &Handler{
mux: http.NewServeMux(),
store: store,
playInterval: playInterval,
playPeriod: playPeriod,
}
h.mux.HandleFunc("GET /", h.getQuizPage)
h.mux.HandleFunc("POST /", h.handleQuizForm)
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)
return h
}