String gender = request.getParameter("gender");
String nameLike = request.getParameter("keyword");
int no = Integer.parseInt(request.getParameter("no"));
Pageable pageable = new PageRequest(Math.max(no, 0),
ApplicationConfig.masonryPageSize,
new Sort(new Order(Direction.DESC, "createdAt")));
if(ApplicationConfig.defaultCityPinyin.equals(city)){
city = "";
}
if(StringUtils.hasText(gender)){
gender = gender.toUpperCase();
try{
Gender g = Gender.valueOf(gender);
gender = g.name();
}catch(RuntimeException re){
logger.error(re.getMessage());
}
}
Collection<PinUserVo> pins = new ArrayList<PinUserVo>();
Page<User> users = null;
// if(StringUtils.hasText(city) && g != null && StringUtils.hasText(keyword)){
// users = userRepository.findByCityAndGenderAndNameLike(city, g, keyword, pageable);
// }else if(StringUtils.hasText(city) && g!=null && !StringUtils.hasText(keyword)){
// users = userRepository.findByCityAndGender(city, g, pageable);
// }else if(StringUtils.hasText(city) && g==null && StringUtils.hasText(keyword)){
// users = userRepository.findByCityAndNameLike(city, keyword, pageable);
// }else if(!StringUtils.hasText(city) && g!=null && StringUtils.hasText(keyword)){
// users = userRepository.findByGenderAndNameLike(g, keyword, pageable);
// }else if(!StringUtils.hasText(city) && g==null && StringUtils.hasText(keyword)){
// users = userRepository.findByNameLike(keyword, pageable);
// }else if(!StringUtils.hasText(city) && g!=null && !StringUtils.hasText(keyword)){
// users = userRepository.findByGender(g, pageable);
// }else if(StringUtils.hasText(city) && g==null && !StringUtils.hasText(keyword)){
// users = userRepository.findByCity(city, pageable);
// }else{
// users = userRepository.findAll(pageable);
// }
users = userRepository.search(StringUtils.trimWhitespace(city),
StringUtils.trimWhitespace(gender),
StringUtils.trimWhitespace(nameLike), pageable);
pageable = new PageRequest(Math.max(no, 0),
ApplicationConfig.masonryThumbPageSize,
new Sort(new Order(Direction.DESC, "updatedAt")));
if(users!=null){
for(User user : users){
Page<Spot> spots = spotRepository.findByCreatedBy(user.getId(), pageable);
pins.add(PinUserVo.from(user, spots.getContent()));
}