package com.ntlab.irisserver.resources; import com.ntlab.irisserver.entities.DrawingController; import com.ntlab.irisserver.entities.Game; import com.ntlab.irisserver.entities.Room; import com.ntlab.irisserver.models.RoomManager; import org.springframework.stereotype.Component; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @Component @Path("/rooms") public class AssignmentRest { //GETでニックネームを貰うと、いま書いてほしいdnoを返す @GET @Path("/{rid}/game/drawings/assignment/{nickname}") @Produces(MediaType.APPLICATION_JSON) public int getDno(@PathParam("rid") String rid,@PathParam("nickname") String nickname ) { Integer dno = null; RoomManager rm = RoomManager.getInstance(); Room room = rm.getRoom(rid); if(room != null) { Game game = room.getGame(); DrawingController drawingController = game.getDrawingController(); dno = drawingController.getDno(nickname); // dno = new Integer(drawingController.getDno(nickname)); if(dno == null ){ //プレイヤーがいなければエラー var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("プレイヤーが存在しません"); throw new WebApplicationException(response.build()); } }else{ //部屋がなければエラー var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); } return dno; } @GET @Path("/{rid}/game/drawings/assignment/timer") @Produces(MediaType.APPLICATION_JSON) public Integer getTime(@PathParam("rid") String rid){ Integer countdown = null; RoomManager rm = RoomManager.getInstance(); Room room = rm.getRoom(rid); if(room != null) { Game game = room.getGame(); DrawingController drawingController = game.getDrawingController(); //絵を描ける時間を取得 countdown = drawingController.getCountdown(); }else{ //部屋がなければエラー var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); } return countdown; } }