@Override public UserDTO findOne(Long id) { User user = userRepository.findOne(id); UserDTO userDto = new UserDTO(); userDto.toDTO(user); return userDto; }
/** * Metodo que se va a utilizar para crear los usuarios * * @param userDto TODO: Queda por hacer el tema de los updates * @return */ @Override public UserDTO saveAndFlush(UserDTO userDto) { Role iniciado = roleRepository.findOne(1L); User u = userDto.toEntity(null, iniciado); u.setPassword(passwordEncoder.encode(userDto.getPassword())); u = userRepository.saveAndFlush(u); userDto.toDTO(u); return userDto; }
public Page<UserDTO> findAll(Integer page, Integer size) { PageRequest pageable = new PageRequest(page, size); Page<User> users = userRepository.findAll(pageable); List<UserDTO> userDTOs = new ArrayList<>(); for (User user : users.getContent()) { UserDTO userDto = new UserDTO(); userDto.toDTO(user); userDTOs.add(userDto); } Page<UserDTO> pages = new PageImpl<>(userDTOs, pageable, users.getTotalElements()); return pages; }
/** * TODO: Hay que mirar una forma de rellenar los beans mas eficiente, ya que a veces no vendra el * usuario completo, si no solo una parte. * * @param user * @return */ @Override public UserDTO updateAndFlush(UserDTO user, boolean updatePassword, boolean updateRole) { User u = userRepository.findOne(user.getUserId()); u = user.updateEntity(u); if (updatePassword) { if (user.getPassword() != null) if (!passwordEncoder.matches(user.getPassword(), u.getPassword())) { u.setPassword(passwordEncoder.encode(user.getPassword())); } } if (updateRole) { Role rol = roleRepository.findOne(user.getRole().getRoleId()); if (!rol.equals(u.getRole())) { u.setRole(rol); } } u = userRepository.saveAndFlush(u); user.toDTO(u); return user; }
private User findByEmailAndUserStateEnum(String email, UserStateEnum state) { return userRepository.findUserByEmailAndUserState(email, state); }
@Override public User findByEmail(String email) { return userRepository.findUserByEmail(email); }
@Override public void delete(User user) { userRepository.delete(user); }
@Override public void delete(Long id) { userRepository.delete(id); }
@Override public User save(User save) { return userRepository.save(save); }