package com.ntlab.irisserver.resources; 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.Response; @Component @Path("/rooms") public class MemberRest { // チーム変更・役職変更のメソッド @Path("/{rid}/members/{nickname}") @PUT public String putMember(@PathParam("rid") String rid, @PathParam("nickname") String nickname, @FormParam("belongs") String belongs, @FormParam("is-master") boolean is_master) { RoomManager rm = RoomManager.getInstance(); Room room = rm.getRoom(rid); if(room != null && room.getMember(nickname) != null) { room.changeTeamAndMaster(nickname, belongs, is_master); }else{ //部屋がなければエラー var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); } return "変更しました"; } // プレイヤーを退出させるメソッド @Path("/{rid}/members/{nickname}") @DELETE public String deleteMember(@PathParam("rid") String rid, @PathParam("nickname") String nickname) { RoomManager rm = RoomManager.getInstance(); Room room = rm.getRoom(rid); if(room != null && room.getMember(nickname) != null) { room.deleteMember(nickname); }else{ //部屋がなければエラー var response = Response.status(Response.Status.NO_CONTENT); response.status(404).entity("部屋が存在しません"); throw new WebApplicationException(response.build()); } return "退出しました"; } }