Feat: end turn endpoint
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user