Prechádzať zdrojové kódy

Changed joining from PUT to POST and comment for API difference from wiki

Ronald Peterson 10 rokov pred
rodič
commit
3c13ae5769
2 zmenil súbory, kde vykonal 4 pridanie a 12 odobranie
  1. 1 1
      board/tile.go
  2. 3 11
      urlrouter.go

+ 1 - 1
board/tile.go

@@ -34,7 +34,7 @@ func (t Tile) String() string {
 func (t Tile) Name() string {
 	switch t {
 	case Water:
-		return "W"
+		return "W" // API says WATER... zucht.
 	case Rock:
 		return "R"
 	case Ice:

+ 3 - 11
urlrouter.go

@@ -16,7 +16,8 @@ func newUrlRouter() *httprouter.Router {
 	router.GET("/", showIndex)
 	router.GET("/games", listGames)
 	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/:boardid", getProxyHandler)
 	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) {
 	w.Header().Set("Content-Type", "application/json")
 	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) {
 	w.Header().Set("Content-Type", "application/json")
-	idString := ps.ByName("rows") // gameId... zucht.
+	idString := ps.ByName("gameid")
 	gameId, _ := strconv.ParseInt(idString, 10, 64)
 	var player player.Player
 	d := json.NewDecoder(r.Body)