@Repository
public interface UserRepository extends PagingAndSortingRepository<UserEntity, Long> {
UserEntity findByEmail(String email);
UserEntity findByUserId(String userId);
}
@GetMapping
public List<UserResponse> getUsers(@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "limit", defaultValue = "25") int limit) {
List<UserResponse> returnValue = new ArrayList<>();
List<UserDto> users = userService.getUsers(page, limit);
for(UserDto userDto: users) {
UserResponse userResponse = new UserResponse();
BeanUtils.copyProperties(userDto, userResponse);
returnValue.add(userResponse);
}
return returnValue;
}
@Override
public List<UserDto> getUsers(int page, int limit) {
List<UserDto> returnValue = new ArrayList<>();
Pageable pageableRequest = PageRequest.of(page, limit);
Page<UserEntity> userPage = userRepository.findAll(pageableRequest);
List<UserEntity> users = userPage.getContent();
for(UserEntity userEntity : users) {
UserDto userDto = new UserDto();
BeanUtils.copyProperties(userEntity, userDto);
returnValue.add(userDto);
}
return returnValue;
}