Skip to content

Commit

Permalink
feature: Issues #413 Add more granular options for substance consumpt…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
andresousadotpt committed Oct 11, 2024
1 parent 7fc3661 commit 969cbc7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 20 deletions.
62 changes: 47 additions & 15 deletions src/main/java/com/nonononoki/alovoa/config/EventListenerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,41 @@ public void handleContextRefresh(ApplicationStartedEvent event) {

private void setDefaultUserMiscInfo() {
if(userMiscInfoRepo.count() == 0) {
UserMiscInfo drugsTobaccoInfo = new UserMiscInfo();
drugsTobaccoInfo.setValue(UserMiscInfo.DRUGS_TOBACCO);

UserMiscInfo drugsAlcoholInfo = new UserMiscInfo();
drugsAlcoholInfo.setValue(UserMiscInfo.DRUGS_ALCOHOL);

UserMiscInfo drugsCannabisInfo = new UserMiscInfo();
drugsCannabisInfo.setValue(UserMiscInfo.DRUGS_CANNABIS);

UserMiscInfo drugsOtherInfo = new UserMiscInfo();
drugsOtherInfo.setValue(UserMiscInfo.DRUGS_OTHER);
UserMiscInfo drugsTobaccoInfoYes = new UserMiscInfo();
drugsTobaccoInfoYes.setValue(UserMiscInfo.DRUGS_TOBACCO_YES);

UserMiscInfo drugsTobaccoInfoNo = new UserMiscInfo();
drugsTobaccoInfoNo.setValue(UserMiscInfo.DRUGS_TOBACCO_NO);

UserMiscInfo drugsTobaccoInfoSometimes = new UserMiscInfo();
drugsTobaccoInfoSometimes.setValue(UserMiscInfo.DRUGS_TOBACCO_SOMETIMES);

UserMiscInfo drugsAlcoholInfoYes = new UserMiscInfo();
drugsAlcoholInfoYes.setValue(UserMiscInfo.DRUGS_ALCOHOL_YES);

UserMiscInfo drugsAlcoholInfoNo = new UserMiscInfo();
drugsAlcoholInfoNo.setValue(UserMiscInfo.DRUGS_ALCOHOL_NO);

UserMiscInfo drugsAlcoholInfoSometimes = new UserMiscInfo();
drugsAlcoholInfoSometimes.setValue(UserMiscInfo.DRUGS_ALCOHOL_SOMETIMES);

UserMiscInfo drugsCannabisInfoYes = new UserMiscInfo();
drugsCannabisInfoYes.setValue(UserMiscInfo.DRUGS_CANNABIS_YES);

UserMiscInfo drugsCannabisInfoNo = new UserMiscInfo();
drugsCannabisInfoNo.setValue(UserMiscInfo.DRUGS_CANNABIS_NO);

UserMiscInfo drugsCannabisInfoSometimes = new UserMiscInfo();
drugsCannabisInfoSometimes.setValue(UserMiscInfo.DRUGS_CANNABIS_SOMETIMES);

UserMiscInfo drugsOtherInfoYes = new UserMiscInfo();
drugsOtherInfoYes.setValue(UserMiscInfo.DRUGS_OTHER_YES);

UserMiscInfo drugsOtherInfoNo = new UserMiscInfo();
drugsOtherInfoNo.setValue(UserMiscInfo.DRUGS_OTHER_NO);

UserMiscInfo drugsOtherInfoSometimes = new UserMiscInfo();
drugsOtherInfoSometimes.setValue(UserMiscInfo.DRUGS_OTHER_SOMETIMES);


UserMiscInfo relationshipSingleInfo = new UserMiscInfo();
Expand All @@ -117,10 +141,18 @@ private void setDefaultUserMiscInfo() {
kidsYesInfo.setValue(UserMiscInfo.KIDS_YES);

userMiscInfoRepo.saveAllAndFlush(Arrays.asList(
drugsTobaccoInfo,
drugsAlcoholInfo,
drugsCannabisInfo,
drugsOtherInfo,
drugsTobaccoInfoYes,
drugsTobaccoInfoNo,
drugsTobaccoInfoSometimes,
drugsAlcoholInfoYes,
drugsAlcoholInfoNo,
drugsAlcoholInfoSometimes,
drugsCannabisInfoYes,
drugsCannabisInfoNo,
drugsCannabisInfoSometimes,
drugsOtherInfoYes,
drugsOtherInfoNo,
drugsOtherInfoSometimes,
relationshipSingleInfo,
relationshipTakenInfo,
relationshipOpenInfo,
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/com/nonononoki/alovoa/entity/user/UserMiscInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
public class UserMiscInfo {

@Transient
public static final long DRUGS_TOBACCO = 1;
public static final long DRUGS_TOBACCO_YES = 1;
@Transient
public static final long DRUGS_ALCOHOL = 2;
public static final long DRUGS_ALCOHOL_YES = 2;
@Transient
public static final long DRUGS_CANNABIS = 3;
public static final long DRUGS_CANNABIS_YES = 3;
@Transient
public static final long DRUGS_OTHER = 4;
public static final long DRUGS_OTHER_YES = 4;

@Transient
public static final long RELATIONSHIP_SINGLE = 11;
@Transient
Expand All @@ -44,6 +44,24 @@ public class UserMiscInfo {
@Transient
public static final long KIDS_YES = 22;

@Transient
public static final long DRUGS_TOBACCO_NO = 31;
@Transient
public static final long DRUGS_ALCOHOL_NO = 32;
@Transient
public static final long DRUGS_CANNABIS_NO = 33;
@Transient
public static final long DRUGS_OTHER_NO = 34;

@Transient
public static final long DRUGS_TOBACCO_SOMETIMES = 41;
@Transient
public static final long DRUGS_ALCOHOL_SOMETIMES = 42;
@Transient
public static final long DRUGS_CANNABIS_SOMETIMES = 43;
@Transient
public static final long DRUGS_OTHER_SOMETIMES = 44;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/nonononoki/alovoa/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.security.*;
import java.util.List;
import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -55,6 +56,12 @@ public class UserService {
private static final String MIME_WAV = "wav";
private static final String MIME_MPEG = "mpeg";
private static final String MIME_MP3 = "mp3";

private final Set<Long> drugsAlcohol = new HashSet<>(Set.of(UserMiscInfo.DRUGS_ALCOHOL_YES, UserMiscInfo.DRUGS_ALCOHOL_SOMETIMES, UserMiscInfo.DRUGS_ALCOHOL_NO));
private final Set<Long> drugsTobacco = new HashSet<>(Set.of(UserMiscInfo.DRUGS_TOBACCO_YES, UserMiscInfo.DRUGS_TOBACCO_SOMETIMES, UserMiscInfo.DRUGS_TOBACCO_NO));
private final Set<Long> drugsCannabis = new HashSet<>(Set.of(UserMiscInfo.DRUGS_CANNABIS_YES, UserMiscInfo.DRUGS_CANNABIS_SOMETIMES, UserMiscInfo.DRUGS_CANNABIS_NO));
private final Set<Long> drugsOther = new HashSet<>(Set.of(UserMiscInfo.DRUGS_OTHER_YES, UserMiscInfo.DRUGS_OTHER_SOMETIMES, UserMiscInfo.DRUGS_OTHER_NO));

@Autowired
private AuthService authService;
@Autowired
Expand Down Expand Up @@ -513,6 +520,14 @@ public Set<UserMiscInfo> updateUserMiscInfo(long infoValue, boolean activated) t
} else if (infoValue >= UserMiscInfo.RELATIONSHIP_SINGLE && infoValue <= UserMiscInfo.RELATIONSHIP_OTHER) {
list.removeIf(o -> o.getValue() != infoValue && o.getValue() >= UserMiscInfo.RELATIONSHIP_SINGLE
&& o.getValue() <= UserMiscInfo.RELATIONSHIP_OTHER);
} else if (drugsAlcohol.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsAlcohol, infoValue));
} else if (drugsTobacco.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsAlcohol, infoValue));
} else if (drugsCannabis.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsCannabis, infoValue));
} else if (drugsOther.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsOther, infoValue));
}

} else {
Expand All @@ -523,6 +538,10 @@ public Set<UserMiscInfo> updateUserMiscInfo(long infoValue, boolean activated) t
return list;
}

private Predicate<UserMiscInfo> conditionToRemoveIfExistent(final Set<Long> options, final long infoValue) {
return c -> options.contains(c.getValue()) && c.getValue() != infoValue;
}

public void addInterest(String value) throws AlovoaException {
User user = authService.getCurrentUser(true);

Expand Down

0 comments on commit 969cbc7

Please sign in to comment.