diff --git a/src/main/java/com/ntlab/irisserver/entities/Turn.java b/src/main/java/com/ntlab/irisserver/entities/Turn.java index dac1b89..e34d5db 100644 --- a/src/main/java/com/ntlab/irisserver/entities/Turn.java +++ b/src/main/java/com/ntlab/irisserver/entities/Turn.java @@ -18,7 +18,7 @@ @JsonProperty("max") private int max; - private Map> questions = new HashMap<>(); + private List> questions = new ArrayList<>(); //> private List openlist = new ArrayList<>(); @@ -42,24 +42,26 @@ public int getMax() {return max;} - public List getOpenLists() {return openlist;} + public List getOpenListAll() {return openlist;} //リストそのものを返す。 - public Map> getQuestionsMap() {return questions;} + public List> getQuestionsList() {return questions;} //--------------------------------------------------------- //questions操作 - public List getQuestions(Cell card){return questions.get(card);} + public List getQuestions(int cno){return questions.get(cno);} - public void addQuestions(Cell card, Member m){questions.get(card).add(m);} + public void addQuestions(int cno, Member m){questions.get(cno).add(m);} - public void delieteQuestions(Cell card, Member m){} //Listのキーが分からない状態での削除どうやんの? + public void delieteQuestions(int cno, Member m){ + + } //Listのキーが分からない状態での削除どうやんの? public int sizeQuestions(){return questions.size();} //openlist操作 - public Cell getOpenList(int num){return openlist.get(num);} + public Cell getOpenListSolo(int num){return openlist.get(num);} public void addOpenList(Cell card){openlist.add(card);} diff --git a/src/main/java/com/ntlab/irisserver/resources/TurnsRest.java b/src/main/java/com/ntlab/irisserver/resources/TurnsRest.java new file mode 100644 index 0000000..ae441f7 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/TurnsRest.java @@ -0,0 +1,145 @@ +package com.ntlab.irisserver.resources; +import org.springframework.stereotype.Component; +import com.ntlab.irisserver.models.RoomManager; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.Turn; +import com.ntlab.irisserver.entities.Cell; +import com.ntlab.irisserver.entities.Member; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; +import java.util.Iterator; + +@Component +@Path("/rooms") + + +public class TurnsRest { + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns: + + @GET //現在のターンの取得 + @Path("/{rid}/game/turns") + public int getTurnNumber(@PathParam("rid") String rid) { + + int tn = 0; + + return tn; + } + + @POST //新しいターンの作成 + @Path("/{rid}/game/turns") + @Produces(MediaType.APPLICATION_JSON) + public Turn addTurns(@PathParam("rid") String rid, @FormParam("nickname") String owner) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + game.createTurn(); + Turn t =game.getTurn(0); + + return t; + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}: + + @GET //Turnインスタンスの取得 + @Path("/{rid}/game/turns/{tno}") + @Produces(MediaType.APPLICATION_JSON) + public Turn getTurns(@PathParam("rid") String rid, @PathParam("tno") Integer tno) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + if (t == null) { + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + return t; + } + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/hint: + + @PUT + @Path("/{rid}/game/turns/{tno}/hint") + public void putHint(@PathParam("rid") String rid, @PathParam("tno") int tno, @FormParam("hint") String hint){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + t.setHint(hint); + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/max: + + @PUT + @Path("/{rid}/game/turns/{tno}/max") + public void putMax(@PathParam("rid") String rid, @PathParam("tno") int tno, @FormParam("hint") int max){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + t.setMax(max); + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/questions: + + @POST //怪しいの切り替え + @Path("/{rid}/game/turns/{tno}/questions") + public void putMax(@PathParam("rid") String rid, @PathParam("tno") int tno, @FormParam("cno") int cno, @FormParam("nickname") String nickname){ + + boolean on = true; + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + List list = t.getQuestions(cno); + for(Iterator it = list.iterator(); it.hasNext();){ + Member m = (Member) it.next(); + if(m.getNickname() == nickname){ + on = false; + break; + } + + } + Member member = room.getMember(nickname); + if(on == true){ + t.addQuestions(cno, member); + }else{ + t.delieteQuestions(cno, member); + } + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/openlist: + + @GET + @Path("/{rid}/game/turns/{tno}/openlist") + public List getOpenList(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getOpenListAll(); + } + +}