diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/LayersRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/LayersRest.java index 88b550c..e0a00e8 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/LayersRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/LayersRest.java @@ -1,7 +1,9 @@ package org.ntlab.acanthus_server.resources.gallery; import org.ntlab.acanthus_server.entities.Layer; +import org.ntlab.acanthus_server.entities.Page; import org.ntlab.acanthus_server.entities.Position; +import org.ntlab.acanthus_server.entities.Stroke; import org.ntlab.acanthus_server.models.Gallery; import org.springframework.stereotype.Component; @@ -27,7 +29,12 @@ @Produces(MediaType.APPLICATION_JSON) public Integer getLayers(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid) { var pages = gallery.getAnimationByAid(aid).getPages(); - return pages.get(pid).getLayers().size(); + for (var p : pages) { + if (!p.getPid().equals(pid)) continue; + return p.getLayers().size(); + } + + throw new WebApplicationException(404); } @@ -40,13 +47,17 @@ @POST @Produces(MediaType.APPLICATION_JSON) public Integer addLayer(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid) { + var layerSize = 4; var pages = gallery.getAnimationByAid(aid).getPages(); + var page = (Page) null; - if (pages.get(pid).getLayers().size() < 4) { - pages.get(pid).getLayers().add(new Layer()); + for (var p : pages) { + if (!p.getPid().equals(pid)) continue; + page = p; + if (p.getLayers().size() < layerSize) p.getLayers().add(new Layer()); } - return pages.get(pid).getLayers().size(); + return page.getLayers().size(); } @@ -61,7 +72,11 @@ @Produces(MediaType.APPLICATION_JSON) public Integer getStrokeNo(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid, @PathParam("layerNo") Integer layerNo) { var pages = gallery.getAnimationByAid(aid).getPages(); - var strokes = pages.get(pid).getLayers().get(layerNo).getStrokes(); + var strokes = new ArrayList(); + for (var p : pages) { + if (pid.equals(p.getPid())) + strokes = p.getLayers().get(layerNo).getStrokes(); + } if (strokes == null) return null; return (strokes.size() - 1);