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 bdf6dab..386bef0 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,7 @@ package org.ntlab.acanthus_server.resources.gallery; +import org.ntlab.acanthus_server.entities.Page; +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 +11,62 @@ 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 pages = new ArrayList<>(); private Gallery gallery = Gallery.getInstance(); + @Path("/{aid}/pageMap/") + @POST + @Produces(MediaType.APPLICATION_JSON) + public Integer addPages(@PathParam("aid") Integer aid) { + var animation = gallery.getAnimationInformation(aid); + + Page page = new Page(); + pages.add(page); + + return pages.size(); + } + + @Path("/{aid}/pageMap/0/layers") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Integer getLayers(@PathParam("aid") Integer aid) { + var animation = gallery.getAnimationInformation(aid); + + return pages.get(0).getLayers().size(); + } + + @Path("/{aid}/pageMap/0/layers") + @POST + @Produces(MediaType.APPLICATION_JSON) + public Integer addLayers(@PathParam("aid") Integer aid) { + var animation = gallery.getAnimationInformation(aid); + + if (pages.get(0).getLayers().size() < 4) { + Layer layer = new Layer(); + pages.get(0).getLayers().add(layer); + } + + return pages.get(0).getLayers().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 pages.get(0).getLayers().get(layerNo).getStrokes(); + // if(animation != null) { // return this.Test; // }else{ @@ -49,17 +85,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 = pages.get(0).getLayers().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{ @@ -71,12 +109,14 @@ // レイヤーごとのstrokeをすべて消去 - @Path("/{aid}/pageMap/0/layers/0/strokes") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes") @DELETE @Produces(MediaType.APPLICATION_JSON) - public String deleteStrokes(@PathParam("aid") Integer aid, @FormParam("uid") Integer uid) { + public String deleteStrokes(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @FormParam("uid") Integer uid) { var animation = gallery.getAnimationInformation(aid); + var strokes = pages.get(0).getLayers().get(layerNo).getStrokes(); + strokes.clear(); return "LGTM?"; // if(animation != null) { @@ -88,12 +128,14 @@ // strokeNoを指定してstrokeを消去 - @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}") @DELETE @Produces(MediaType.APPLICATION_JSON) - public String deleteStrokeNo(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo) { + public String deleteStrokeNo(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @PathParam("strokeNo") Integer strokeNo) { var animation = gallery.getAnimationInformation(aid); + var strokes = pages.get(0).getLayers().get(layerNo).getStrokes(); + int no = strokeNo; strokes.remove(no); return "やかんの麦茶"; @@ -108,12 +150,14 @@ // 全座標値を取得する // @PathParam Integer aid 作品のID // @PathParam Integer strokeNo 線番号 - @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/positions") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}/positions") @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 = pages.get(0).getLayers().get(layerNo).getStrokes(); + Stroke stroke = strokes.get(strokeNo); // 指定したstrokeNoのstrokesを呼び出す return stroke.getPositions(); // 呼び出したstrokesの情報を返す // if(animation != null) { @@ -130,12 +174,14 @@ // @PathParam Integer strokeNo 線番号 // @FormParam Integer x x座標 // @FormParam Integer y y座標 - @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/positions") + @Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}/positions") @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 = pages.get(0).getLayers().get(layerNo).getStrokes(); + Position position = new Position(); position.setXY(x, y); Stroke stroke = strokes.get(strokeNo); // 指定したstrokeNoのstrokesを呼び出す