refactor structure of user to feature based structure
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package SuMoC.backend.user.models;
|
||||
|
||||
import SuMoC.backend.user.enums.FriendShipStatus;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "friendships")
|
||||
public class Friendship {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "friend_id", nullable = false)
|
||||
private User friend;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private FriendShipStatus status;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public Friendship() {
|
||||
}
|
||||
|
||||
public Friendship(Long id, User user, User friend, FriendShipStatus status, LocalDateTime createdAt) {
|
||||
this.id = id;
|
||||
this.user = user;
|
||||
this.friend = friend;
|
||||
this.status = status;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getFriend() {
|
||||
return friend;
|
||||
}
|
||||
|
||||
public void setFriend(User friend) {
|
||||
this.friend = friend;
|
||||
}
|
||||
|
||||
public FriendShipStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(FriendShipStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createAt) {
|
||||
this.createdAt = createAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package SuMoC.backend.user.models;
|
||||
|
||||
|
||||
import SuMoC.backend.trip.Modality;
|
||||
import SuMoC.backend.trip.models.Trip;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "trip_segments")
|
||||
public class TripSegment {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "trip_id", nullable = false)
|
||||
private Trip trip;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private Modality modality;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* Distance of the segment in meters.
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private Long distanceMeters;
|
||||
|
||||
public TripSegment() {}
|
||||
|
||||
public TripSegment(Long id, Trip trip, Modality modality, LocalDateTime startTime, Long distanceMeters) {
|
||||
this.id = id;
|
||||
this.trip = trip;
|
||||
this.modality = modality;
|
||||
this.startTime = startTime;
|
||||
this.distanceMeters = distanceMeters;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Trip getTrip() {
|
||||
return trip;
|
||||
}
|
||||
|
||||
public void setTrip(Trip trip) {
|
||||
this.trip = trip;
|
||||
}
|
||||
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
public void setModality(Modality modality) {
|
||||
this.modality = modality;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public Long getDistanceMeters() {
|
||||
return distanceMeters;
|
||||
}
|
||||
|
||||
public void setDistanceMeters(Long distance) {
|
||||
this.distanceMeters = distance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package SuMoC.backend.user.models;
|
||||
|
||||
import SuMoC.backend.user.enums.RoleName;
|
||||
import SuMoC.backend.user.enums.VisibilityPrivacy;
|
||||
import SuMoC.backend.trip.models.Trip;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@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)
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO getter for friend users?
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user