Skip to content

Commit

Permalink
improve search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
s39f4lt committed Jan 5, 2021
1 parent 3087ee8 commit 855a238
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ public class UserController {
};

public static Route search = (request, response) -> {
Integer ageFrom = nonNull(request.queryParams("agefrom")) ? parseInt(request.queryParams("agefrom")) : null;
Integer ageTo = nonNull(request.queryParams("ageto")) ? parseInt(request.queryParams("ageto")) : null;
Integer rateTo = nonNull(request.queryParams("rateto")) ? parseInt(request.queryParams("rateto")) : null;
Integer rateFrom = nonNull(request.queryParams("ratefrom")) ? parseInt(request.queryParams("ratefrom")) : null;
FormDto formDto = new FormDto(
null,
Boolean.parseBoolean(request.queryParams("man")),
Boolean.parseBoolean(request.queryParams("woman")),
parseInt(request.queryParams("agefrom")),
parseInt(request.queryParams("ageto")),
parseInt(request.queryParams("ratefrom")),
parseInt(request.queryParams("rateto")),
ageFrom,
ageTo,
rateFrom,
rateTo,
parseInt(request.queryParams("radius"))
);
String tags = request.queryParams("tags");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public List<User> search(long userId, Form form, List<String> tags) {
if (user.getBirthday() != null) {
Date userBirthday = user.getBirthday();
int years = Years.yearsBetween(new DateTime(userBirthday), new DateTime()).getYears();
if (years <= form.getAgeFrom() || years >= form.getAgeTo()) {
if (isNull(form.getAgeFrom()) && isNull(form.getAgeTo())) {
return false;
}
if (nonNull(form.getAgeFrom()) && years <= form.getAgeFrom()) {
return false;
}
if (nonNull(form.getAgeTo()) && years >= form.getAgeTo()) {
return false;
}
}
Expand Down

0 comments on commit 855a238

Please sign in to comment.