@Transactional public void addUserChannel(final int id, final Channel channel) { List<User> users = userDao.getUserById(id); if (users.size() == 1) { users.get(0).getChannels().add(channel); } else if (users.size() == 0) { LOGGER.warn("User with that id doesn't exist"); } else { LOGGER.warn("Duplicates were found in table 'users'"); } }
@Test public void testAddUser() throws Exception { LOGGER.debug("test: addUser"); Integer id_user = userDao.addUser(user); assertNotNull(id_user); User newUser = userDao.getUserById(id_user); assertEquals(user.getLogin(), newUser.getLogin()); assertEquals(user.getPassword(), newUser.getPassword()); assertEquals(user.getFirstname(), newUser.getFirstname()); assertEquals(user.getLastname(), newUser.getLastname()); }
@Transactional public boolean updateUserChannels(final int id, final List<Channel> channels) { List<User> users = userDao.getUserById(id); if (users.size() == 1) { users.get(0).setChannels(channels); return true; } else if (users.size() == 0) { return false; } else { LOGGER.warn("Duplicates were found in table 'users'"); return false; } }