diff --git a/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java b/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java index 344e615..1b82722 100644 --- a/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java +++ b/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java @@ -1,6 +1,7 @@ package com.ntlab.irisserver.resources; import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.entities.Settings; import com.ntlab.irisserver.models.RoomManager; import org.springframework.stereotype.Component; @@ -19,29 +20,28 @@ @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{rid}/settings") - public Object GetSettings(@PathParam("rid") String rid) { + public Settings getSettings(@PathParam("rid") String rid) { Room r = rm.getRoom(rid); - //部屋が存在しないとき - var response = Response.status(Response.Status.NO_CONTENT); - if(r == null) { + //部屋がある時、JsonでSettingsの情報を返す + if(r != null) { + Settings settings = r.getSettings(); + return settings; + + } else { + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); } - else return - "drawingTime:" + r.isDrawingTimer()+ ",\n" + - "drawingTimerTimes:" + r.getDrawingTimerTimes() + ",\n" + - "gameTimer:" + r.isGameTimer() +",\n" + - "gameTimerTimes:" + r.getGameTimerTimes() + ",\n" + - "gameTimerInitializeTimes:" + r.getGameTimerFirstThinkingTimes(); } //---------------------------------------------------------------------------------------------------- //PUT:設定値の変更 @PUT @Path("/{rid}/settings") - public void PutSettings(@PathParam("rid") String rid, + public void putSettings(@PathParam("rid") String rid, @FormParam("drawingTimer") boolean dTimer, @FormParam("drawingTimerTimes") int dTimerTimes, @FormParam("gameTimer") boolean gTimer, @@ -49,17 +49,22 @@ @FormParam("gameTimerFirstThinkingTimes") int gTimerFTTimes) { Room r = rm.getRoom(rid); + var response = Response.status(Response.Status.NO_CONTENT); //部屋がある時、値を変更 - if(r != null) { - r.setDrawingTimer(dTimer); - r.setDrawingTimerTimes(dTimerTimes); - r.setGameTimer(gTimer); - r.setGameTimerTimes(gTimerTimes); - r.setGameTimerFirstThinkingTimes(gTimerFTTimes); - }else{ + if (r != null) { + Settings settings = r.getSettings(); + + settings.setDrawingTimer(dTimer); + settings.setDrawingTimerTimes(dTimerTimes); + settings.setGameTimer(gTimer); + settings.setGameTimerTimes(gTimerTimes); + settings.setGameTimerFirstThinkingTimes(gTimerFTTimes); + + response.status(200).entity("値変更完了"); + throw new WebApplicationException(response.build()); + } else { //部屋がなければエラー - var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); }