42 lines
928 B
Go
42 lines
928 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"forge.cadoles.com/wpetit/kouiz/internal/store"
|
|
"forge.cadoles.com/wpetit/kouiz/internal/timex"
|
|
"github.com/bornholm/genai/llm"
|
|
)
|
|
|
|
type Handler struct {
|
|
mux *http.ServeMux
|
|
store *store.Store
|
|
llm llm.Client
|
|
|
|
playInterval time.Duration
|
|
playPeriod timex.PeriodType
|
|
}
|
|
|
|
// ServeHTTP implements http.Handler.
|
|
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
h.mux.ServeHTTP(w, r)
|
|
}
|
|
|
|
func NewHandler(store *store.Store, llm llm.Client, playInterval time.Duration, playPeriod timex.PeriodType) *Handler {
|
|
h := &Handler{
|
|
mux: http.NewServeMux(),
|
|
store: store,
|
|
llm: llm,
|
|
playInterval: playInterval,
|
|
playPeriod: playPeriod,
|
|
}
|
|
|
|
h.mux.HandleFunc("GET /presentation/leaderboard", h.getLeaderboardPresentation)
|
|
h.mux.HandleFunc("GET /presentation/turn", h.getTurnPresentation)
|
|
|
|
return h
|
|
}
|
|
|
|
var _ http.Handler = &Handler{}
|