knowyt/server/src/application/setGameLang.go

35 lines
731 B
Go
Raw Normal View History

2022-04-24 16:22:23 +00:00
package application
import (
"fmt"
"net/http"
2022-11-06 14:41:13 +00:00
"sirlab.de/go/knowyt/log"
2022-04-24 16:22:23 +00:00
"sirlab.de/go/knowyt/user"
)
func (app *Application) SetGameLang(usr *user.User, w http.ResponseWriter, r *http.Request) {
gameRef := r.URL.Query().Get("g")
gm, err := app.GetGameById(gameRef)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "game not found")
return
}
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintf(w, "forbidden")
return
}
lang := r.URL.Query().Get("lang")
if err := gm.SetGameLang(lang); err != nil {
w.WriteHeader(http.StatusInternalServerError)
2022-11-06 14:41:13 +00:00
log.ErrorLog(err)
2022-04-24 16:22:23 +00:00
fmt.Fprintf(w, "server error")
return
}
fmt.Fprintf(w, "ok")
}