Feat: end turn endpoint

This commit is contained in:
Grail Finder
2025-05-08 20:04:09 +03:00
parent 3cc2ecb93d
commit 8baf03595e
7 changed files with 51 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package handlers
import (
"context"
"errors"
"golias/models"
"html/template"
"net/http"
@ -125,3 +126,30 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) {
}
tmpl.ExecuteTemplate(w, "base", fi)
}
func HandleEndTurn(w http.ResponseWriter, r *http.Request) {
// get username
fi, err := getFullInfoByCtx(r.Context())
if err != nil {
abortWithError(w, err.Error())
return
}
// check if one who pressed it is from the team who has the turn
if fi.Room.TeamTurn != string(fi.State.Team) {
err = errors.New("unexpected team turn:" + fi.Room.TeamTurn)
abortWithError(w, err.Error())
return
}
fi.Room.ChangeTurn()
if err := saveFullInfo(fi); err != nil {
abortWithError(w, err.Error())
return
}
// return html
tmpl, err := template.ParseGlob("components/*.html")
if err != nil {
abortWithError(w, err.Error())
return
}
tmpl.ExecuteTemplate(w, "base", fi)
}