diff --git a/src/main/java/cactusServer/resources/InstancesRest.java b/src/main/java/cactusServer/resources/InstancesRest.java index 43027fc..cfecfdd 100644 --- a/src/main/java/cactusServer/resources/InstancesRest.java +++ b/src/main/java/cactusServer/resources/InstancesRest.java @@ -1,5 +1,6 @@ package cactusServer.resources; +import java.util.HashMap; import java.util.HashSet; import javax.ws.rs.FormParam; @@ -21,12 +22,10 @@ import cactusServer.entities.CameraState; import cactusServer.entities.Character; import cactusServer.entities.EmoteState; -import cactusServer.entities.IDAddressedEntity; import cactusServer.entities.Instance; import cactusServer.entities.Instance.State; import cactusServer.entities.Plain; import cactusServer.entities.Player; -import cactusServer.entities.URIAddressedEntity; import cactusServer.models.Instances; @Path("/instances") @@ -51,8 +50,9 @@ @Path("/{instanceId}") @GET @Produces(MediaType.APPLICATION_JSON) - public Instance getInstance(@PathParam("instanceId") String instanceId) { - return Instances.getInstance().getInstance(instanceId); + public Instances getInstance(@PathParam("name") String name, @FormParam("state") State state, + @FormParam("stageID") String stageID) { + return Instances.getInstance(); } @Path("/{instanceId}/areas/{areaId}") @@ -68,27 +68,38 @@ @POST @Produces(MediaType.APPLICATION_JSON) - public URIAddressedEntity createInstance(@FormParam("name") String name, @FormParam("state") Instance.State state, - @FormParam("stageModel") String stageModel) { - IDAddressedEntity ae = Instances.getInstance().createInstance(name, state, stageModel); - return new URIAddressedEntity((INSTANCES_URI + "/" + ae.getId()), ae.getBody()); + public HashMap createInstance(@FormParam("name") String name, @FormParam("stageID") int stageID) { + HashMap idMap = Instances.getInstance().createInstance(name, stageID); + HashMap uriMap = new HashMap<>(); + for (String id : idMap.keySet()) { + String uri = (INSTANCES_URI + "/") + id; + uriMap.put(uri, idMap.get(id)); + } + return uriMap; } @Path("/{instanceId}/areas") @POST @Produces(MediaType.APPLICATION_JSON) - public URIAddressedEntity createArea(@PathParam("instanceId") String instanceId, @FormParam("name") String name, + public HashMap createArea(@PathParam("instanceId") String instanceId, @FormParam("name") String name, @FormParam("region") Plain[] region, @FormParam("permissions") HashSet permissions) { Instance instance = Instances.getInstance().getInstance(instanceId); - IDAddressedEntity ae = instance.createArea(name, region, permissions); - return new URIAddressedEntity((INSTANCES_URI + "/" + instanceId + "/areas/" + ae.getId()), ae.getBody()); + HashMap idMap = instance.createArea(name, region, permissions); + HashMap uriMap = new HashMap<>(); + for (String id : idMap.keySet()) { + String uri = (INSTANCES_URI + "/" + instanceId + "/areas") + id; + uriMap.put(uri, idMap.get(id)); + } + return uriMap; } - -// @PUT -// @Produces(MediaType.APPLICATION_JSON) -// public Instance updateInstance(@FormParam("state") Instance.State state) { -// return Instances.getInstance().updateInstance(name, state, stageID); -// } + + @Path("/{instanceId}") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public Instance updateInstance(@PathParam("instanceId") String instanceId, @FormParam("state") Instance.State state) { + Instance instance = Instances.getInstance().getInstance(instanceId); + return instance.update(state); + } // @Path("/{instanceId}") // @PUT