package application import ( "fmt" "net/http" "sirlab.de/go/knyt/user" ) func (app *Application) SaveQuote(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 } quoteId := r.URL.Query().Get("id") quoteText := r.URL.Query().Get("quote") if err := gm.SaveQuote(usr.GetId(), quoteId, quoteText); err != nil { fmt.Printf("%s\n", err) w.WriteHeader(http.StatusForbidden) fmt.Fprintf(w, "forbidden") return } }