freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
changeset 43 58b8db5faf2c
parent 42 c5726abc1218
child 44 85a0fad6b3c2
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Tue Aug 11 14:51:47 2009 +0200
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Tue Aug 11 15:17:23 2009 +0200
     1.3 @@ -42,6 +42,7 @@
     1.4  import java.util.Iterator;
     1.5  import java.util.List;
     1.6  import java.util.Map;
     1.7 +import javax.ws.rs.DefaultValue;
     1.8  import javax.ws.rs.GET;
     1.9  import javax.ws.rs.Path;
    1.10  import javax.ws.rs.PathParam;
    1.11 @@ -81,13 +82,34 @@
    1.12      }
    1.13  
    1.14      @GET
    1.15 -    @Path("games/{id}")
    1.16 +    @Path("games/{id}/")
    1.17      public Viewable board(@PathParam("id") String id) throws JSONException {
    1.18          Object obj = convert(base.path("games").path(id).accept(MediaType.TEXT_PLAIN_TYPE).get(String.class));
    1.19          return new Viewable("game.fmt", obj);
    1.20      }
    1.21  
    1.22      @GET
    1.23 +    @Path("games/{id}/move")
    1.24 +    public Viewable move(
    1.25 +        @PathParam("id") String id,
    1.26 +        @QueryParam("type") String type,
    1.27 +        @QueryParam("direction") String direction,
    1.28 +        @QueryParam("direction-next") @DefaultValue("") String directionNext,
    1.29 +        @QueryParam("column") @DefaultValue("") String column,
    1.30 +        @QueryParam("row") @DefaultValue("") String row
    1.31 +    ) throws JSONException {
    1.32 +        if (type.equals("fence")) {
    1.33 +            base.path("games").path(id).queryParam("move", direction.charAt(0) + column + row).post();
    1.34 +            return board(id);
    1.35 +        }
    1.36 +        if (type.equals("move")) {
    1.37 +            base.path("games").path(id).queryParam("move", direction + directionNext);
    1.38 +            return board(id);
    1.39 +        }
    1.40 +        return board(id);
    1.41 +    }
    1.42 +
    1.43 +    @GET
    1.44      @Path("games/create")
    1.45      public Viewable create(
    1.46          @QueryParam("white") String white,