Skip to content

Commit

Permalink
Update Tools.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Dec 27, 2024
1 parent 225db68 commit 8a695c0
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/main/java/com/nonononoki/alovoa/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,22 @@ public static boolean usersCompatible(User user1, User user2, boolean ignoreInte
|| user2.getDates() == null) {
return false;
}

int user1Age = calcUserAge(user1);
int user2Age = calcUserAge(user2);

return (user2.getLikes() != null && user2.getLikes().stream().filter(u -> u.getUserTo() != null)
.map(u -> u.getUserTo().getId()).anyMatch(u ->
Objects.equals(u, user1.getId()))) || user2Age < AGE_LEGAL == user1Age < AGE_LEGAL
&& user2.getPreferedGenders().contains(user1.getGender())
&& user1.getPreferedGenders().contains(user2.getGender()) && user1.getPreferedMaxAge() >= user2Age
&& user1.getPreferedMinAge() <= user2Age && user2.getPreferedMaxAge() >= user1Age
&& user2.getPreferedMinAge() <= user1Age
&& (ignoreIntention || user2.getIntention().getId().equals(user1.getIntention().getId()));
boolean compatible;
try {
compatible = (user2.getLikes() != null && user2.getLikes().stream().filter(u -> u.getUserTo() != null)
.map(u -> u.getUserTo().getId()).anyMatch(u ->
Objects.equals(u, user1.getId()))) || user2Age < AGE_LEGAL == user1Age < AGE_LEGAL
&& user2.getPreferedGenders().contains(user1.getGender())
&& user1.getPreferedGenders().contains(user2.getGender()) && user1.getPreferedMaxAge() >= user2Age
&& user1.getPreferedMinAge() <= user2Age && user2.getPreferedMaxAge() >= user1Age
&& user2.getPreferedMinAge() <= user1Age
&& (ignoreIntention || user2.getIntention().getId().equals(user1.getIntention().getId()));
} catch (Exception e) {
compatible = false;
}
return compatible;
}

// This method subtracts user date of birth with passed preferred min/max age
Expand Down Expand Up @@ -266,24 +270,26 @@ public static String getAuthParams(SecurityConfig securityConfig, String httpSes

public static UUID getProfilePictureUUID(UserProfilePicture image, UserService userService) {
UUID uuid = image.getUuid();
if(uuid == null) {
if (uuid == null) {
uuid = UUID.randomUUID();
userService.updateProfilePictureUUID(image, uuid);
}
return uuid;
}

public static UUID getImageUUID(UserImage image, UserService userService) {
UUID uuid = image.getUuid();
if(uuid == null) {
if (uuid == null) {
uuid = UUID.randomUUID();
userService.updateImageUUID(image, uuid);
}
return uuid;
}

public static UUID getUserUUID(User user, UserService userService) {

UUID uuid = user.getUuid();
if(uuid == null) {
if (uuid == null) {
uuid = UUID.randomUUID();
userService.updateUUID(user, uuid);
}
Expand Down

0 comments on commit 8a695c0

Please sign in to comment.