diff --git a/handlers/elements.go b/handlers/elements.go index a3be4c8..dfdac93 100644 --- a/handlers/elements.go +++ b/handlers/elements.go @@ -61,7 +61,16 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { Color: color, Revealed: true, } - fi.Room.RevealSpecificWord(word) + revCardID := fi.Room.RevealSpecificWord(word) + if revCardID == 0 { + // error + abortWithError(w, "word has 0 id") + return + } + if err := repo.WordCardReveal(r.Context(), word, fi.Room.ID); err != nil { + abortWithError(w, err.Error()) + return + } fi.Room.UpdateCounter() action := models.Action{ Actor: fi.State.Username, diff --git a/models/main.go b/models/main.go index 6c2a3db..047610c 100644 --- a/models/main.go +++ b/models/main.go @@ -376,12 +376,14 @@ func (r *Room) GuesserView() { } } -func (r *Room) RevealSpecificWord(word string) { +func (r *Room) RevealSpecificWord(word string) uint32 { for i, card := range r.Cards { if card.Word == word { r.Cards[i].Revealed = true + return card.ID } } + return 0 } type WordCard struct {