Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / models / RoomManager.java
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<String, Room> rooms = new HashMap<String, Room>();

    @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);
    }


}