feat: initial commit
This commit is contained in:
@ -1,11 +1,15 @@
|
||||
package quiz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/auth"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/common"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/quiz/component"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/store"
|
||||
"github.com/a-h/templ"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -25,6 +29,8 @@ func (h *Handler) fillQuizPageVModel(r *http.Request) (*component.QuizPageVModel
|
||||
|
||||
err := common.FillViewModel(
|
||||
r.Context(), vmodel, r,
|
||||
h.fillQuizPagePlayer,
|
||||
h.fillQuizPageTurn,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
@ -33,6 +39,35 @@ func (h *Handler) fillQuizPageVModel(r *http.Request) (*component.QuizPageVModel
|
||||
return vmodel, nil
|
||||
}
|
||||
|
||||
func (h *Handler) fillQuizPagePlayer(ctx context.Context, vmodel *component.QuizPageVModel, r *http.Request) error {
|
||||
user := auth.ContextUser(ctx)
|
||||
|
||||
player := &store.Player{
|
||||
Name: user.Name,
|
||||
UserID: user.ID,
|
||||
UserProvider: user.Provider,
|
||||
}
|
||||
|
||||
if err := h.store.UpsertPlayer(ctx, player); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
vmodel.Player = player
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Handler) fillQuizPageTurn(ctx context.Context, vmodel *component.QuizPageVModel, r *http.Request) error {
|
||||
turn, err := h.store.GetQuizTurn(ctx, h.playInterval)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
spew.Dump(turn)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Handler) handleQuizForm(w http.ResponseWriter, r *http.Request) {
|
||||
quizForm := component.NewQuizForm()
|
||||
|
||||
|
Reference in New Issue
Block a user