Search in sources :

Example 6 with User

use of com.mapia.domain.User in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class UserRepository method findUserByNickname.

public User findUserByNickname(String nickname) {
    String query = "SELECT * FROM User WHERE nickname = ?";
    List<User> resultUser;
    try {
        resultUser = jdbcTemplate.query(query, (rs, rowNum) -> {
            User user = new User();
            user.setId(rs.getLong("id"));
            user.setEmail(rs.getString("email"));
            user.setPassword(rs.getString("password"));
            user.setNickname(rs.getString("nickname"));
            return user;
        }, nickname);
    } catch (EmptyResultDataAccessException e) {
        log.error(e.getMessage());
        return null;
    }
    return resultUser.size() > 0 ? resultUser.get(0) : null;
}
Also used : List(java.util.List) User(com.mapia.domain.User) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Repository(org.springframework.stereotype.Repository) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) User(com.mapia.domain.User) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 7 with User

use of com.mapia.domain.User in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class RoomController method enter.

@GetMapping("/{id}")
public String enter(@PathVariable long id, HttpSession session, Model model) {
    if (!HttpSessionUtils.isLoginUser(session)) {
        return "redirect:/login";
    }
    User user = HttpSessionUtils.getUserFromSession(session);
    if (!lobby.isExistRoom(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        if (!user.isLobby()) {
            exitUserFromRoom(user);
        }
        return "redirect:/";
    }
    Room room = lobby.getRoom(id);
    if (!user.isAbleToEnter(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        exitUserFromRoom(user);
        return "redirect:/";
    }
    if (room.isFull()) {
        return "redirect:/lobby";
    }
    if (room.isSecretMode()) {
    //TODO Add secret mode logic
    }
    //        room.getUsers().forEach(ser -> ser.ready()); // FOR TEST USE ONLY
    room.enter(user);
    model.addAttribute("room", room);
    model.addAttribute("user", user);
    return "room";
}
Also used : User(com.mapia.domain.User) Room(com.mapia.domain.Room)

Example 8 with User

use of com.mapia.domain.User in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class RoomController method exit.

@DeleteMapping("")
public String exit(HttpSession session) {
    User user = HttpSessionUtils.getUserFromSession(session);
    exitUserFromRoom(user);
    return "redirect:/lobby";
}
Also used : User(com.mapia.domain.User)

Example 9 with User

use of com.mapia.domain.User in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class GameManagerTest method assignRole.

@Test
public void assignRole() {
    users.add(new User());
    users.add(new User());
    users.add(new User());
    users.add(new User());
    users.add(new User());
    GameManager gm = new GameManager(users);
}
Also used : User(com.mapia.domain.User) GameManager(com.mapia.game.GameManager) Test(org.junit.Test)

Example 10 with User

use of com.mapia.domain.User in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class ApiRoomController method enter.

@GetMapping("/{id}")
public RoomResult enter(@PathVariable long id, HttpSession session, Model model) {
    if (!HttpSessionUtils.isLoginUser(session)) {
        return RoomResult.invalidAccess(id);
    }
    User user = HttpSessionUtils.getUserFromSession(session);
    if (!lobby.isExistRoom(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        if (!user.isLobby()) {
            exitUserFromRoom(user);
        }
        return RoomResult.invalidAccess(id);
    }
    Room room = lobby.getRoom(id);
    if (!user.isAbleToEnter(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        exitUserFromRoom(user);
        return RoomResult.invalidAccess(id);
    }
    if (room.isFull()) {
        return RoomResult.rejectToEnterRoomOfFull(id);
    }
    if (room.isSecretMode()) {
    //TODO Add secret mode logic
    }
    room.enter(user);
    model.addAttribute("room", room);
    model.addAttribute("user", user);
    return RoomResult.successToEnterRoom(id);
}
Also used : User(com.mapia.domain.User) Room(com.mapia.domain.Room)

Aggregations

User (com.mapia.domain.User)10 Room (com.mapia.domain.Room)2 List (java.util.List)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 Repository (org.springframework.stereotype.Repository)2 GameManager (com.mapia.game.GameManager)1 Test (org.junit.Test)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1