knowyt/server/src/application/setGameName.go

33 lines
707 B
Go
Raw Normal View History

2022-03-01 08:41:30 +00:00
package application
import (
"fmt"
"net/http"
"sirlab.de/go/knowyt/user"
2022-03-01 08:41:30 +00:00
)
func (app *Application) SetGameName(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
}
name := r.URL.Query().Get("name")
if err := gm.SetGameName(name); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Printf("%v", err)
fmt.Fprintf(w, "server error")
return
}
fmt.Fprintf(w, "ok")
}