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; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Path("rooms") public class SettingsRest { RoomManager rm = RoomManager.getInstance(); //------------------------------------------------------------------------------------ //GET:設定情報の入手 @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{rid}/settings") public Settings getSettings(@PathParam("rid") String rid) { Room r = rm.getRoom(rid); //部屋がある時、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()); } } //---------------------------------------------------------------------------------------------------- //PUT:設定値の変更 @PUT @Path("/{rid}/settings") public void putSettings(@PathParam("rid") String rid, @FormParam("drawingTimer") boolean dTimer, @FormParam("drawingTimerTimes") int dTimerTimes, @FormParam("gameTimer") boolean gTimer, @FormParam("gameTimerTimes") int gTimerTimes, @FormParam("gameTimerFirstThinkingTimes") int gTimerFTTimes) { Room r = rm.getRoom(rid); var response = Response.status(Response.Status.NO_CONTENT); //部屋がある時、値を変更 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 { //部屋がなければエラー response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); } } }