diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Layer.java b/src/main/java/org/ntlab/acanthus_server/entities/Layer.java new file mode 100644 index 0000000..c4a89d6 --- /dev/null +++ b/src/main/java/org/ntlab/acanthus_server/entities/Layer.java @@ -0,0 +1,16 @@ +package org.ntlab.acanthus_server.entities; + +import java.util.ArrayList; + +public class Layer { + private ArrayList strokes = new ArrayList<>(); + + public ArrayList getStrokes() { + return this.strokes; + } + + public void setStrokes(ArrayList strokes) { + this.strokes = strokes; + } + +} diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Layers.java b/src/main/java/org/ntlab/acanthus_server/entities/Layers.java deleted file mode 100644 index e6f860d..0000000 --- a/src/main/java/org/ntlab/acanthus_server/entities/Layers.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.ntlab.acanthus_server.entities; - -public class Layers { -} diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java index eca4230..5e0453f 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java @@ -1,5 +1,6 @@ package org.ntlab.acanthus_server.resources.gallery; +import org.ntlab.acanthus_server.entities.Layer; import org.ntlab.acanthus_server.entities.Position; import org.ntlab.acanthus_server.entities.Stroke; import org.ntlab.acanthus_server.entities.Work; @@ -9,28 +10,50 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; @Component @Path("/gallery") public class StrokesRest { - private ArrayList strokes = new ArrayList<>(); + private ArrayList layers = new ArrayList<>(); private Gallery gallery = Gallery.getInstance(); + @Path("/{aid}/pageMap/0/layers") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Integer getLayers(@PathParam("aid") Integer aid) { + var animation = gallery.getAnimationInformation(aid); + + return layers.size(); + } + + @Path("/{aid}/pageMap/0/layers") + @POST + @Produces(MediaType.APPLICATION_JSON) + public Integer addLayers(@PathParam("aid") Integer aid) { + var animation = gallery.getAnimationInformation(aid); + + if (layers.size() < 4) { + Layer layer = new Layer(); + layers.add(layer); + } + + return layers.size(); + } + // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // 1ページの1レイヤーに置ける筆跡情報を全て取得します // 成功時のレスポンス:strokeNo{pen, color, thickness, potions{x, y}} // @PathParam Integer aid 作品ID // @PathParam Integer pid ページのID 今回は0 // @PathParam Integer layerNo レイヤーの番号 今回は0 - @Path("/{aid}/pageMap/0/layers/0/strokes") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes") @GET @Produces(MediaType.APPLICATION_JSON) - public ArrayList getStrokeRest(@PathParam("aid") Integer aid) { + public ArrayList getStrokeRest(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo) { var animation = gallery.getAnimationInformation(aid); - return this.strokes; + return layers.get(layerNo).getStrokes(); + // if(animation != null) { // return this.Test; // }else{ @@ -49,17 +72,19 @@ // @Formparam Integer pen ペン情報 // @Formparam Integer color 色情報 // @Formparam Integer thick 太さ情報 - @Path("/{aid}/pageMap/0/layers/0/strokes") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes") @POST @Produces(MediaType.APPLICATION_JSON) - public Integer addStrokes(@PathParam("aid") Integer aid, @FormParam("uid") Integer uid, @FormParam("uidToken") String uidToken, + public Integer addStrokes(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @FormParam("uid") Integer uid, @FormParam("uidToken") String uidToken, @FormParam("pen") Integer pen, @FormParam("color") Integer color, @FormParam("thick") Integer thick) { var animation = gallery.getAnimationInformation(aid); + var strokes = layers.get(layerNo).getStrokes(); + Stroke stroke = new Stroke(); stroke.addStrokes(pen, color, thick); // 線の情報を追加 stroke.setStrokeNo(strokes.size()); // strokeNoに現在のstrokesのsizeを入れる - this.strokes.add(stroke); + strokes.add(stroke); // if(animation != null) { // this.Test.setStrokes(pen, color, thick); // }else{ @@ -74,12 +99,14 @@ // 全座標値を取得する // @PathParam Integer aid 作品のID // @PathParam Integer strokeNo 線番号 - @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/position") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}/position") @GET @Produces(MediaType.APPLICATION_JSON) - public ArrayList getPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo) { + public ArrayList getPositions(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @PathParam("strokeNo") Integer strokeNo) { var animation = gallery.getAnimationInformation(aid); + var strokes = layers.get(layerNo).getStrokes(); + Stroke stroke = strokes.get(strokeNo); // 指定したstrokeNoのstrokesを呼び出す return stroke.getPositions(); // 呼び出したstrokesの情報を返す // if(animation != null) { @@ -96,12 +123,14 @@ // @PathParam Integer strokeNo 線番号 // @FormParam Integer x x座標 // @FormParam Integer y y座標 - @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/position") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}/position") @POST @Produces(MediaType.APPLICATION_JSON) - public Integer addPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo, @FormParam("x") Float x, @FormParam("y") Float y) { + public Integer addPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo, @PathParam("layerNo") Integer layerNo, @FormParam("x") Float x, @FormParam("y") Float y) { var animation = gallery.getAnimationInformation(aid); + var strokes = layers.get(layerNo).getStrokes(); + Position position = new Position(); position.setXY(x, y); Stroke stroke = strokes.get(strokeNo); // 指定したstrokeNoのstrokesを呼び出す