# HG changeset patch # User Jaroslav Tulach # Date 1249995107 -7200 # Node ID c5726abc1218a30542dfed981b553655e14aeb59 # Parent c94f68ddef596738b59b0f5a5f109518723a6b21 Can create new game diff -r c94f68ddef59 -r c5726abc1218 freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Aug 11 14:26:49 2009 +0200 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Aug 11 14:51:47 2009 +0200 @@ -45,7 +45,12 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Request; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; @@ -55,15 +60,22 @@ * @author Jaroslav Tulach */ @Path("/") -@Singleton public final class UI { private static WebResource base; + + @Context + private Request request; + @Context + private HttpHeaders headers; + public UI() { } @GET - @Path("/") public Viewable welcome() throws JSONException { + if (headers.getCookies().containsKey("login")) { + } + Object obj = getJson(base.path("games")); return new Viewable("index.fmt", obj); } @@ -72,9 +84,22 @@ @Path("games/{id}") public Viewable board(@PathParam("id") String id) throws JSONException { Object obj = convert(base.path("games").path(id).accept(MediaType.TEXT_PLAIN_TYPE).get(String.class)); + return new Viewable("game.fmt", obj); + } - System.err.println("obj: " + obj); - return new Viewable("game.fmt", obj); + @GET + @Path("games/create") + public Viewable create( + @QueryParam("white") String white, + @QueryParam("black") String black + ) throws JSONException { + Object obj = convert( + base.path("games").queryParam("white", white). + queryParam("black", black).post(JSONObject.class) + ); + Map map = (Map)obj; + String id = (String)map.get("id"); + return board(id); } diff -r c94f68ddef59 -r c5726abc1218 freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Tue Aug 11 14:26:49 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Tue Aug 11 14:51:47 2009 +0200 @@ -12,5 +12,10 @@
  • ${item.white} vs. ${item.black} board
  • +
    + White: + Black: + +
    \ No newline at end of file