Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / resources / MemberRest.java
package com.ntlab.irisserver.resources;

import com.ntlab.irisserver.entities.Member;
import com.ntlab.irisserver.entities.Room;
import com.ntlab.irisserver.models.RoomManager;
import org.springframework.stereotype.Component;

import javax.ws.rs.*;
import java.util.List;

@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");
        List<Member> m = room.getMembers();
        room.changeTeamAndMaster(nickname, belongs, is_master);
        return "変更しました";
    }

    // プレイヤーを退出させるメソッド
    @Path("/{rid}/members/{nickname}")
    @DELETE
    public String deleteMember(@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");
        List<Member> m = room.getMembers();
        for( int i = 0; i < 10; i++ ) {
            Member name = m.get(i);
            if ( nickname.equals(name.getNickname()) ) {
                //room.deleteMember(nickname, belongs, is_master);
            }
        }

        return "退出しました";
    }
}