diff --git a/src/main/java/com/ntlab/irisserver/resources/StateRest.java b/src/main/java/com/ntlab/irisserver/resources/StateRest.java new file mode 100644 index 0000000..5f6e482 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/StateRest.java @@ -0,0 +1,46 @@ +package com.ntlab.irisserver.resources; + +import org.springframework.stereotype.Component; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + + +@Component +@Path("/rooms") + +public class StateRest { + + @GET//部屋の情報を入手 + @Path("/{rid}/state") + public int getState(@PathParam("rid") String rid) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + if(room==null){ + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + return room.state; //部屋の情報を送る + } +//---------------------------------------------------------------------------------------------------------------------------------- + @PUT//部屋の情報を変更する + @Path("/{rid}/state") + //rid,nickname,stateを引数として持ってくる + public void putState(@PathParam("rid") String rid,@FormParam("nickname") String nickname,@FormParam("state") Integer state) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + if(nickname.equals(room.ownerName)){ //nicknameがownerだった場合 + room.state = state; //部屋の情報を変更 + } + } + + +} \ No newline at end of file