LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
1. /data/ is readonly on macOS -> changed to ./keys/ 2. Changed Friendcode Annotation to unique
184 lines
5.0 KiB
Java
184 lines
5.0 KiB
Java
package SuMoC.backend.user.models;
|
|
|
|
import SuMoC.backend.gamification.badges.models.UserBadge;
|
|
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 java.util.*;
|
|
|
|
@Entity
|
|
@Table(name = "users")
|
|
public class User {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
/**
|
|
* The public name of the user, displayed in public leaderboards etc.
|
|
*/
|
|
@Column(unique = true, nullable = false, length = 50)
|
|
private String publicName;
|
|
|
|
/**
|
|
* The private name of the user, used in private leaderboards, shown to friends etc.
|
|
*/
|
|
@Column(nullable = false)
|
|
private String privateName;
|
|
|
|
@Column(unique = true, nullable = false)
|
|
private String email;
|
|
|
|
@Column(nullable = false)
|
|
private String password;
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
@Column(nullable = false)
|
|
private VisibilityPrivacy visibilityPrivacy;
|
|
|
|
@Column(nullable = false, unique = true, length = 36)
|
|
private String friendCode;
|
|
|
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
private Set<Trip> trips = new HashSet<>();
|
|
|
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
private Set<Friendship> friendships = new HashSet<>();
|
|
|
|
@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;
|
|
|
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
|
|
private Set<UserBadge> badges = new HashSet<>();
|
|
|
|
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
private StatsList statsList;
|
|
|
|
public User() {}
|
|
|
|
// public User(Long id, String publicName, String privateName, String email, String password, VisibilityPrivacy visibilityPrivacy, String friendCode, Set<Trip> trips, Set<Friendship> friendships, Set<RoleName> roles) {
|
|
// this.id = id;
|
|
// this.publicName = publicName;
|
|
// this.privateName = privateName;
|
|
// this.email = email;
|
|
// this.password = password;
|
|
// this.visibilityPrivacy = visibilityPrivacy;
|
|
// this.friendCode = friendCode;
|
|
// this.trips = trips;
|
|
// this.friendships = friendships;
|
|
// this.roles = roles;
|
|
// }
|
|
|
|
public User(String publicName, String privateName, String email, String password) {
|
|
this.publicName = publicName;
|
|
this.privateName = privateName;
|
|
this.email = email;
|
|
this.password = password;
|
|
this.visibilityPrivacy = VisibilityPrivacy.NONE;
|
|
this.friendCode = java.util.UUID.randomUUID().toString(); // generate unique friend code
|
|
this.roles = new HashSet<>();
|
|
this.roles.add(RoleName.USER);
|
|
this.statsList = new StatsList(this);
|
|
}
|
|
|
|
@PrePersist
|
|
private void ensureFriendCode() {
|
|
if (this.friendCode == null) {
|
|
this.friendCode = UUID.randomUUID().toString();
|
|
}
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getPublicName() {
|
|
return publicName;
|
|
}
|
|
|
|
public void setPublicName(String publicName) {
|
|
this.publicName = publicName;
|
|
}
|
|
|
|
public String getPrivateName() {
|
|
return privateName;
|
|
}
|
|
|
|
public void setPrivateName(String privateName) {
|
|
this.privateName = privateName;
|
|
}
|
|
|
|
public String getEmail() {
|
|
return email;
|
|
}
|
|
|
|
public void setEmail(String email) {
|
|
this.email = email;
|
|
}
|
|
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
|
|
public VisibilityPrivacy getVisibilityPrivacy() {
|
|
return visibilityPrivacy;
|
|
}
|
|
|
|
public void setVisibilityPrivacy(VisibilityPrivacy visibilityPrivacy) {
|
|
this.visibilityPrivacy = visibilityPrivacy;
|
|
}
|
|
|
|
public String getFriendCode() {
|
|
return friendCode;
|
|
}
|
|
|
|
public void setFriendCode(String friendCode) {
|
|
this.friendCode = friendCode;
|
|
}
|
|
|
|
public Set<Trip> getTrips() {
|
|
return trips;
|
|
}
|
|
|
|
public void setTrips(Set<Trip> trips) {
|
|
this.trips = trips;
|
|
}
|
|
|
|
public Set<Friendship> getFriendships() {
|
|
return friendships;
|
|
}
|
|
|
|
public void setFriendships(Set<Friendship> friendships) {
|
|
this.friendships = friendships;
|
|
}
|
|
|
|
public Set<RoleName> getRoles() {
|
|
return roles;
|
|
}
|
|
|
|
public void setRoles(Set<RoleName> roles) {
|
|
this.roles = roles;
|
|
}
|
|
|
|
public Set<UserBadge> getBadges() { return badges; }
|
|
|
|
public void setBadges(Set<UserBadge> badges) { this.badges = badges; }
|
|
|
|
public StatsList getStats() { return statsList;}
|
|
|
|
public void setStats(StatsList statsList) { this.statsList = statsList; }
|
|
}
|