53 lines
1.2 KiB
Java
53 lines
1.2 KiB
Java
package SuMoC.backend.user.models;
|
|
|
|
import SuMoC.backend.user.enums.FriendShipStatus;
|
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
|
import jakarta.persistence.*;
|
|
import lombok.*;
|
|
|
|
import java.time.Instant;
|
|
|
|
/**
|
|
* For explanation of statuses, also see "getFriendships" in UserController.
|
|
*/
|
|
@Setter
|
|
@Getter
|
|
@Entity
|
|
@Builder
|
|
@AllArgsConstructor
|
|
@NoArgsConstructor
|
|
@Table(
|
|
name = "friendships",
|
|
uniqueConstraints = @UniqueConstraint(columnNames = {"user_id", "friend_id"})
|
|
)
|
|
public class Friendship {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@ManyToOne
|
|
@JoinColumn(name = "user_id", nullable = false)
|
|
@JsonBackReference("user-friendships")
|
|
private User user;
|
|
|
|
@ManyToOne
|
|
@JoinColumn(name = "friend_id", nullable = false)
|
|
@JsonBackReference("friend-friendships")
|
|
private User friend;
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
@Column(nullable = false)
|
|
private FriendShipStatus status;
|
|
|
|
@Column(nullable = false)
|
|
private Instant createdAt;
|
|
|
|
public Friendship(User user, User friend, FriendShipStatus status) {
|
|
this.user = user;
|
|
this.friend = friend;
|
|
this.status = status;
|
|
this.createdAt = Instant.now();
|
|
}
|
|
|
|
}
|