Merge branch 'main' into cachingAndPP
# Conflicts: # src/main/java/SuMoC/backend/gamification/badges/BadgeController.java # src/main/java/SuMoC/backend/gamification/scoretable/LeaderboardController.java # src/main/java/SuMoC/backend/gamification/scoretable/LeaderboardService.java # src/main/java/SuMoC/backend/user/controller/UserController.java # src/main/java/SuMoC/backend/user/models/User.java
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
package SuMoC.backend.user.models;
|
||||
|
||||
import SuMoC.backend.gamification.badges.models.UserBadge;
|
||||
import SuMoC.backend.notification.models.NotificationToken;
|
||||
import SuMoC.backend.routing.models.RoutingPreferences;
|
||||
import SuMoC.backend.trip.models.Trip;
|
||||
import SuMoC.backend.user.enums.RoleName;
|
||||
import SuMoC.backend.user.enums.VisibilityPrivacy;
|
||||
import SuMoC.backend.user.stats.StatsList;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
@@ -38,7 +43,7 @@ public class User {
|
||||
@Column(nullable = false)
|
||||
private VisibilityPrivacy visibilityPrivacy;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(nullable = false, unique = true, length = 36)
|
||||
private String friendCode;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@@ -47,18 +52,27 @@ public class User {
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Set<Friendship> friendships = new HashSet<>();
|
||||
|
||||
@Setter
|
||||
@ElementCollection(targetClass = RoleName.class, fetch = FetchType.EAGER)
|
||||
@Enumerated(EnumType.STRING)
|
||||
@CollectionTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@Column(name = "role")
|
||||
private Set<RoleName> roles;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "id", referencedColumnName = "user_id")
|
||||
private NotificationToken notificationToken;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
|
||||
private Set<UserBadge> badges = new HashSet<>();
|
||||
|
||||
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private StatsList statsList;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "routing_preferences_id", unique = true)
|
||||
private RoutingPreferences routingPreferences;
|
||||
|
||||
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private ProfileImageEntity profileImage;
|
||||
|
||||
@@ -84,12 +98,20 @@ public class User {
|
||||
this.password = password;
|
||||
this.visibilityPrivacy = VisibilityPrivacy.NONE;
|
||||
this.friendCode = java.util.UUID.randomUUID().toString(); // generate unique friend code
|
||||
this.routingPreferences = RoutingPreferences.getDefaultPreferences(); // Init with default routing preferences
|
||||
this.roles = new HashSet<>();
|
||||
this.roles.add(RoleName.USER);
|
||||
this.statsList = new StatsList(this);
|
||||
this.profileImage = new ProfileImageEntity(this, null);
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
private void ensureFriendCode() {
|
||||
if (this.friendCode == null) {
|
||||
this.friendCode = UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -166,17 +188,37 @@ public class User {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Set<RoleName> roles) {
|
||||
this.roles = roles;
|
||||
public Set<UserBadge> getBadges() {
|
||||
return badges;
|
||||
}
|
||||
|
||||
public Set<UserBadge> getBadges() { return badges; }
|
||||
public void setBadges(Set<UserBadge> badges) {
|
||||
this.badges = badges;
|
||||
}
|
||||
|
||||
public void setBadges(Set<UserBadge> badges) { this.badges = badges; }
|
||||
public StatsList getStats() {
|
||||
return statsList;
|
||||
}
|
||||
|
||||
public StatsList getStats() { return statsList;}
|
||||
public void setStats(StatsList statsList) {
|
||||
this.statsList = statsList;
|
||||
}
|
||||
|
||||
public void setStats(StatsList statsList) { this.statsList = statsList; }
|
||||
public NotificationToken getNotificationToken() {
|
||||
return notificationToken;
|
||||
}
|
||||
|
||||
public void setNotificationToken(NotificationToken notificationToken) {
|
||||
this.notificationToken = notificationToken;
|
||||
}
|
||||
|
||||
public RoutingPreferences getRoutingPreferences() {
|
||||
return routingPreferences;
|
||||
}
|
||||
|
||||
public void setRoutingPreferences(RoutingPreferences routingPreferences) {
|
||||
this.routingPreferences = routingPreferences;
|
||||
}
|
||||
|
||||
public ProfileImageEntity getProfileImage() {
|
||||
return profileImage;
|
||||
|
||||
Reference in New Issue
Block a user