positon[s]に修正
commit cc28b6fec3cbd229c4eb28ae3d1285beab934bf1
2 parents 2aa3214 + 0e7c86a
t-tai authored on 22 Jun 2021
Showing 1 changed file
View
81
src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java
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;
import org.ntlab.acanthus_server.models.Gallery;
 
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<Page> pages = new ArrayList<>();
private ArrayList<Stroke> strokes = 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/{layerNo}/strokes")
@Path("/{aid}/pageMap/0/layers/0/strokes")
@GET
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<Stroke> getStrokeRest(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo) {
public ArrayList<Stroke> getStrokeRest(@PathParam("aid") Integer aid) {
var animation = gallery.getAnimationInformation(aid);
 
return pages.get(0).getLayers().get(layerNo).getStrokes();
 
return this.strokes;
// if(animation != null) {
// return this.Test;
// }else{
// throw new WebApplicationException(401);
// @FormParam Integer uidToken トークン
// @Formparam Integer pen ペン情報
// @Formparam Integer color 色情報
// @Formparam Integer thick 太さ情報
@Path("/{aid}/pageMap/0/layers/{layerNo}/strokes")
@Path("/{aid}/pageMap/0/layers/0/strokes")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Integer addStrokes(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @FormParam("uid") Integer uid, @FormParam("uidToken") String uidToken,
public Integer addStrokes(@PathParam("aid") Integer aid, @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を入れる
strokes.add(stroke);
this.strokes.add(stroke);
// if(animation != null) {
// this.Test.setStrokes(pen, color, thick);
// }else{
// throw new WebApplicationException(401);
}
 
 
// レイヤーごとのstrokeをすべて消去
@Path("/{aid}/pageMap/0/layers/{layerNo}/strokes")
@Path("/{aid}/pageMap/0/layers/0/strokes")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public String deleteStrokes(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @FormParam("uid") Integer uid) {
public String deleteStrokes(@PathParam("aid") Integer aid, @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) {
}
 
 
// strokeNoを指定してstrokeを消去
@Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}")
@Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public String deleteStrokeNo(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @PathParam("strokeNo") Integer strokeNo) {
public String deleteStrokeNo(@PathParam("aid") Integer aid, @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 "やかんの麦茶";
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// 全座標値を取得する
// @PathParam Integer aid 作品のID
// @PathParam Integer strokeNo 線番号
@Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}/position")
@Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/positions")
@GET
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<Position> getPositions(@PathParam("aid") Integer aid, @PathParam("layerNo") Integer layerNo, @PathParam("strokeNo") Integer strokeNo) {
public ArrayList<Position> getPositions(@PathParam("aid") Integer aid, @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) {
// @PathParam Integer aid 作品のID
// @PathParam Integer strokeNo 線番号
// @FormParam Integer x x座標
// @FormParam Integer y y座標
@Path("/{aid}/pageMap/0/layers/{layerNo}/strokes/{strokeNo}/position")
@Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/positions")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Integer addPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo, @PathParam("layerNo") Integer layerNo, @FormParam("x") Float x, @FormParam("y") Float y) {
public Integer addPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo, @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を呼び出す