package application import ( "encoding/json" "fmt" "net/http" "sirlab.de/go/knyt/user" ) func (app *Application) GetQuotes(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 } quotesInfo, err := gm.GetQuotesInfoByUser(usr) if err != nil { fmt.Println(err) w.WriteHeader(http.StatusForbidden) fmt.Fprintf(w, "forbidden") return } w.Header().Add("Content-Type", "application/json") jsonString, _ := json.Marshal(quotesInfo) fmt.Fprintf(w, string(jsonString)) }