|
@@ -16,7 +16,8 @@ func newUrlRouter() *httprouter.Router {
|
|
|
router.GET("/", showIndex)
|
|
router.GET("/", showIndex)
|
|
|
router.GET("/games", listGames)
|
|
router.GET("/games", listGames)
|
|
|
router.PUT("/games", createGame)
|
|
router.PUT("/games", createGame)
|
|
|
- router.PUT("/games/:rows/:cols", putProxyHandler)
|
|
|
|
|
|
|
+ router.PUT("/games/:rows/:cols", createGame)
|
|
|
|
|
+ router.POST("/games/:gameid/join", joinGame) // API says PUT... zuch.
|
|
|
router.GET("/games/:gameid", showGame)
|
|
router.GET("/games/:gameid", showGame)
|
|
|
router.GET("/games/:gameid/:boardid", getProxyHandler)
|
|
router.GET("/games/:gameid/:boardid", getProxyHandler)
|
|
|
router.GET("/games/:gameid/:boardid/:playerid", showPlayer)
|
|
router.GET("/games/:gameid/:boardid/:playerid", showPlayer)
|
|
@@ -44,15 +45,6 @@ func getProxyHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Param
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func putProxyHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
|
-
|
|
|
|
|
- if ps.ByName("cols") == "join" {
|
|
|
|
|
- joinGame(w, r, ps)
|
|
|
|
|
- } else {
|
|
|
|
|
- createGame(w, r, ps)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func listGames(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
func listGames(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
e := json.NewEncoder(w)
|
|
e := json.NewEncoder(w)
|
|
@@ -79,7 +71,7 @@ func createGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
|
|
|
|
func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
- idString := ps.ByName("rows") // gameId... zucht.
|
|
|
|
|
|
|
+ idString := ps.ByName("gameid")
|
|
|
gameId, _ := strconv.ParseInt(idString, 10, 64)
|
|
gameId, _ := strconv.ParseInt(idString, 10, 64)
|
|
|
var player player.Player
|
|
var player player.Player
|
|
|
d := json.NewDecoder(r.Body)
|
|
d := json.NewDecoder(r.Body)
|