Newer
Older
IrisServerWebSocket / src / main / java / com / ntlab / irisserver / resources / GameRest.java
Kota on 8 Dec 2022 1 KB first commit
package com.ntlab.irisserver.resources;

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

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Component
@Path("/rooms")
public class GameRest {

    @GET
    @Path("/{rid}/game")
    @Produces(MediaType.APPLICATION_JSON)
    public GameJson getGame(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        GameJson gj = new GameJson(game);
        return gj;
    }

    @GET
    @Path("/{rid}/game/map")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Integer> getMap(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        List<Integer> map = game.getMap();
        return map;
    }

    @GET
    @Path("/{rid}/game/color")
    @Produces(MediaType.APPLICATION_JSON)
    public List<String> getColorList(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        List<String> color = game.getColorList();
        return color;
    }

    @GET
    @Path("/{rid}/game/keywords")
    @Produces(MediaType.APPLICATION_JSON)
    public List<String> getKeywords(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        List<String> keywords = game.getKeywords();
        return keywords;
    }

}