knowyt/server/src/application/finishGame.go

30 lines
573 B
Go
Raw Normal View History

2021-09-24 18:46:10 +00:00
package application
import (
"fmt"
"net/http"
"sirlab.de/go/knowyt/user"
2021-09-24 18:46:10 +00:00
)
func (app *Application) FinishGame(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
}
2021-09-26 21:36:47 +00:00
if err := app.saveGameState(gm); err != nil {
2021-09-24 18:46:10 +00:00
fmt.Println(err)
}
gm.FinishGame()
}