diff --git a/src/main/java/com/ntlab/irisserver/models/RoomManager.java b/src/main/java/com/ntlab/irisserver/models/RoomManager.java new file mode 100644 index 0000000..b79d3b2 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/models/RoomManager.java @@ -0,0 +1,45 @@ +package com.ntlab.irisserver.models; +import com.ntlab.irisserver.entities.Room; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@Component +@Path("/rooms") +public class RoomManager { + private static RoomManager theInstance = null; + private Map rooms = new HashMap(); + + @GET + public static RoomManager getInstance(){ + if(theInstance == null){ + theInstance = new RoomManager(); + } + return theInstance; + } + + @PUT + public Room creatRoom(@FormParam("nickname") String owner){ + UUID uuid = UUID.randomUUID(); + String rid = uuid.toString(); //uuid型からstring型に変換 + Room r = new Room(rid, owner); + rooms.put(rid, r); + return r; + } + + @GET + public Room getRoom(@FormParam("rid") String rid){ + Room r = rooms.get(rid); + return r; + } + + @DELETE + public void deleteRoom(@FormParam("rid") String rid){ + rooms.remove(rid); + } + + +}