Skip to content

Commit

Permalink
Add additional misc info fields for profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Dec 9, 2024
1 parent 0f7c5bf commit e40b6a4
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,26 @@ private void setDefaultUserMiscInfo() {
new UserMiscInfo(UserMiscInfo.RELATIONSHIP_OPEN),
new UserMiscInfo(UserMiscInfo.RELATIONSHIP_OTHER),
new UserMiscInfo(UserMiscInfo.KIDS_NO),
new UserMiscInfo(UserMiscInfo.KIDS_YES)
new UserMiscInfo(UserMiscInfo.KIDS_YES),
new UserMiscInfo(UserMiscInfo.RELATIONSHIP_TYPE_MONOGAMOUS),
new UserMiscInfo(UserMiscInfo.RELATIONSHIP_TYPE_POLYAMOROUS),
new UserMiscInfo(UserMiscInfo.GENDER_IDENTITY_CIS),
new UserMiscInfo(UserMiscInfo.GENDER_IDENTITY_TRANS),
new UserMiscInfo(UserMiscInfo.POLITICS_MODERATE),
new UserMiscInfo(UserMiscInfo.POLITICS_LEFT),
new UserMiscInfo(UserMiscInfo.POLITICS_RIGHT),
new UserMiscInfo(UserMiscInfo.RELIGION_NO),
new UserMiscInfo(UserMiscInfo.RELIGION_YES),
new UserMiscInfo(UserMiscInfo.FAMILY_WANT),
new UserMiscInfo(UserMiscInfo.FAMILY_NOT_WANT),
new UserMiscInfo(UserMiscInfo.FAMILY_NOT_UNSURE)
));

userMiscInfoList.removeIf(u -> userMiscInfoRepo.existsByValue(u.getValue()));

userMiscInfoRepo.saveAllAndFlush(userMiscInfoList);
if(!userMiscInfoList.isEmpty()) {
userMiscInfoRepo.saveAllAndFlush(userMiscInfoList);
}
}

public void setDefaultAdmin() {
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/com/nonononoki/alovoa/entity/user/Gender.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package com.nonononoki.alovoa.entity.user;

import java.util.List;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nonononoki.alovoa.entity.User;

import jakarta.persistence.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@EqualsAndHashCode
@Entity
public class Gender {

Expand All @@ -31,16 +24,18 @@ public class Gender {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Exclude
private Long id;

@JsonIgnore
@ManyToMany
@EqualsAndHashCode.Exclude
private List<User> users;

@JsonIgnore
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "gender")
@EqualsAndHashCode.Exclude
private List<User> user;

private String text;

}
2 changes: 2 additions & 0 deletions src/main/java/com/nonononoki/alovoa/entity/user/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import com.nonononoki.alovoa.component.TextEncryptorConverter;
import com.nonononoki.alovoa.entity.User;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@EqualsAndHashCode
@Entity
public class Message {

Expand Down
26 changes: 6 additions & 20 deletions src/main/java/com/nonononoki/alovoa/entity/user/UserInterest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,28 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nonononoki.alovoa.entity.User;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

@Getter
@Setter
@EqualsAndHashCode
@Entity
public class UserInterest {

@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Exclude
private Long id;

private String text;

@JsonIgnore
@ManyToOne
@EqualsAndHashCode.Exclude
private User user;

@Override
public boolean equals(Object o) {

if (o == this) {
return true;
}

if (!(o instanceof UserInterest)) {
return false;
}

UserInterest i = (UserInterest) o;
return i.getText().equals(text);
}

@Override
public int hashCode() {
return this.text.hashCode();
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/nonononoki/alovoa/entity/user/UserMiscInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nonononoki.alovoa.entity.User;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Entity
@EqualsAndHashCode
@NoArgsConstructor
public class UserMiscInfo {

Expand Down Expand Up @@ -64,12 +66,43 @@ public class UserMiscInfo {
@Transient
public static final long DRUGS_OTHER_SOMETIMES = 44;

@Transient
public static final long RELATIONSHIP_TYPE_MONOGAMOUS = 51;
@Transient
public static final long RELATIONSHIP_TYPE_POLYAMOROUS = 52;

@Transient
public static final long GENDER_IDENTITY_CIS = 61;
@Transient
public static final long GENDER_IDENTITY_TRANS = 62;

@Transient
public static final long POLITICS_MODERATE = 71;
@Transient
public static final long POLITICS_LEFT = 72;
@Transient
public static final long POLITICS_RIGHT = 73;

@Transient
public static final long RELIGION_NO = 81;
@Transient
public static final long RELIGION_YES = 82;

@Transient
public static final long FAMILY_WANT = 91;
@Transient
public static final long FAMILY_NOT_WANT = 92;
@Transient
public static final long FAMILY_NOT_UNSURE = 93;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Exclude
private Long id;

@JsonIgnore
@ManyToMany
@EqualsAndHashCode.Exclude
private List<User> users;

@Column(unique=true)
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/nonononoki/alovoa/model/ProfileOnboardingDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

@Data
public class ProfileOnboardingDto {

private Long intention;

private List<Long> preferredGenders;

private String profilePictureMime;
private Long intention;

private String description;

private Set<String> interests;
private List<Long> preferredGenders;

private boolean notificationLike;
private String profilePictureMime;

private String description;

private Set<String> interests;

private boolean notificationLike;

private boolean notificationChat;

private boolean notificationChat;

}
2 changes: 2 additions & 0 deletions src/main/java/com/nonononoki/alovoa/model/UserGdpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class UserGdpr {
private List<UserImage> images;
private List<UserPrompt> prompts;
private List<UserDonation> donations;
private Set<UserMiscInfo> miscInfo;
private List<Message> messageSent;
private UserDates dates;
private boolean showZodiac;
Expand All @@ -60,6 +61,7 @@ public static UserGdpr userToUserGdpr(User user) {
u.setIntention(user.getIntention());
u.setInterests(user.getInterests());
u.setPreferedGenders(user.getPreferedGenders());
u.setMiscInfo(user.getMiscInfos());

u.setAudio(user.getAudio());
u.setProfilePicture(user.getProfilePicture());
Expand Down
76 changes: 49 additions & 27 deletions src/main/java/com/nonononoki/alovoa/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.springframework.http.*;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
Expand All @@ -36,10 +35,16 @@
import javax.sound.sampled.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List;
Expand All @@ -59,10 +64,18 @@ public class UserService {
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));
private final Set<Long> drugsAlcoholMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.DRUGS_ALCOHOL_YES, UserMiscInfo.DRUGS_ALCOHOL_SOMETIMES, UserMiscInfo.DRUGS_ALCOHOL_NO));
private final Set<Long> drugsTobaccoMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.DRUGS_TOBACCO_YES, UserMiscInfo.DRUGS_TOBACCO_SOMETIMES, UserMiscInfo.DRUGS_TOBACCO_NO));
private final Set<Long> drugsCannabisMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.DRUGS_CANNABIS_YES, UserMiscInfo.DRUGS_CANNABIS_SOMETIMES, UserMiscInfo.DRUGS_CANNABIS_NO));
private final Set<Long> drugsOtherMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.DRUGS_OTHER_YES, UserMiscInfo.DRUGS_OTHER_SOMETIMES, UserMiscInfo.DRUGS_OTHER_NO));

private final Set<Long> kidsMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.KIDS_NO, UserMiscInfo.KIDS_YES));
private final Set<Long> relationshipMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.RELATIONSHIP_SINGLE, UserMiscInfo.RELATIONSHIP_TAKEN, UserMiscInfo.RELATIONSHIP_OPEN));
private final Set<Long> politicsMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.POLITICS_MODERATE, UserMiscInfo.POLITICS_LEFT, UserMiscInfo.POLITICS_RIGHT));
private final Set<Long> genderIdentityMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.GENDER_IDENTITY_CIS, UserMiscInfo.GENDER_IDENTITY_TRANS));
private final Set<Long> religionMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.RELIGION_NO, UserMiscInfo.RELIGION_YES));
private final Set<Long> familyMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.FAMILY_WANT, UserMiscInfo.FAMILY_NOT_WANT, UserMiscInfo.FAMILY_NOT_UNSURE));
private final Set<Long> relationshipTypeMiscInfoSet = new HashSet<>(Set.of(UserMiscInfo.RELATIONSHIP_TYPE_POLYAMOROUS, UserMiscInfo.RELATIONSHIP_TYPE_MONOGAMOUS));

@Autowired
private AuthService authService;
Expand Down Expand Up @@ -374,6 +387,7 @@ public void deleteAccountConfirm(UserDeleteAccountDto dto)
mailService.sendAccountDeleteConfirm(user);
}

@SuppressWarnings("deprecation")
public void updateProfilePicture(byte[] bytes, String mimeType) throws AlovoaException, IOException {
User user = authService.getCurrentUser(true);
user.setVerificationPicture(null);
Expand Down Expand Up @@ -507,33 +521,39 @@ public void updatePreferedGender(long genderId, boolean activated) throws Alovoa

public Set<UserMiscInfo> updateUserMiscInfo(long infoValue, boolean activated) throws AlovoaException {
User user = authService.getCurrentUser(true);

Set<UserMiscInfo> list = user.getMiscInfos();
if (list == null) {
list = new HashSet<>();
}

UserMiscInfo info = userMiscInfoRepo.findByValue(infoValue);
if (kidsMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(kidsMiscInfoSet, infoValue));
} else if (relationshipMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(relationshipMiscInfoSet, infoValue));
} else if (drugsAlcoholMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsAlcoholMiscInfoSet, infoValue));
} else if (drugsTobaccoMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsAlcoholMiscInfoSet, infoValue));
} else if (drugsCannabisMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsCannabisMiscInfoSet, infoValue));
} else if (drugsOtherMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(drugsOtherMiscInfoSet, infoValue));
} else if (politicsMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(politicsMiscInfoSet, infoValue));
} else if (genderIdentityMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(genderIdentityMiscInfoSet, infoValue));
} else if (religionMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(religionMiscInfoSet, infoValue));
} else if (familyMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(familyMiscInfoSet, infoValue));
} else if (relationshipTypeMiscInfoSet.contains(infoValue)) {
list.removeIf(conditionToRemoveIfExistent(relationshipTypeMiscInfoSet, infoValue));
}

if (activated) {
UserMiscInfo info = userMiscInfoRepo.findByValue(infoValue);
list.add(info);

if (infoValue >= UserMiscInfo.KIDS_NO && infoValue <= UserMiscInfo.KIDS_YES) {
list.removeIf(o -> o.getValue() != infoValue && o.getValue() >= UserMiscInfo.KIDS_NO
&& o.getValue() <= UserMiscInfo.KIDS_YES);
} 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 {
list.remove(info);
}
user.setMiscInfos(list);
userRepo.saveAndFlush(user);
Expand Down Expand Up @@ -895,6 +915,7 @@ public ResponseEntity<Resource> getUserdata(UUID uuid) throws AlovoaException, J
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}

@SuppressWarnings("deprecation")
public String getAudio(UUID uuid)
throws NumberFormatException, AlovoaException {
User user = findUserByUuid(uuid);
Expand All @@ -910,6 +931,7 @@ public void deleteAudio() throws AlovoaException {
userRepo.saveAndFlush(user);
}

@SuppressWarnings("deprecation")
public void updateAudio(byte[] bytes, String mimeType)
throws AlovoaException, UnsupportedAudioFileException, IOException {
User user = authService.getCurrentUser(true);
Expand Down
Loading

0 comments on commit e40b6a4

Please sign in to comment.