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; import java.util.List; @Component @Path("/rooms") public class RoomsRest { @GET //テスト用(すべての部屋の情報を表示) @Path("/") @Produces(MediaType.APPLICATION_JSON) public List<Room> getRoomsInfo(){ RoomManager rm = RoomManager.getInstance(); rm.getRooms(); List<Room> rms = rm.getRooms(); return rms; } @POST //部屋の作成,オーナーを設定 @Path("/") @Produces(MediaType.APPLICATION_JSON) public Room makeRooms(@FormParam("nickname") String owner){ RoomManager rm = RoomManager.getInstance(); Room room = rm.createRoom(owner); room.addMember(owner); return room; } @GET//部屋の情報を表示 @Path("/{rid}") @Produces(MediaType.APPLICATION_JSON) public Room getRoomMember(@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; } @DELETE//部屋の削除 @Path("/{rid}") public void deleteRooms(@PathParam("rid") String rid){ RoomManager rm = RoomManager.getInstance(); rm.deleteRoom(rid); } }