mirror of
https://github.com/usatiuk/y.git
synced 2025-10-29 02:37:49 +01:00
entities for messages
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
package com.usatiuk.tjv.y.server.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class Chat implements EntityWithId<Long> {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "chat")
|
||||||
|
private Collection<Message> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
@ManyToMany(mappedBy = "chats")
|
||||||
|
private Collection<Person> users;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.usatiuk.tjv.y.server.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class Message implements EntityWithId<Long> {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private Chat chat;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private Person author;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
@NotBlank
|
||||||
|
private String contents;
|
||||||
|
}
|
||||||
@@ -37,6 +37,9 @@ public class Person implements EntityWithId<String> {
|
|||||||
@OneToMany(mappedBy = "author")
|
@OneToMany(mappedBy = "author")
|
||||||
private Collection<Post> posts = new ArrayList<>();
|
private Collection<Post> posts = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "author")
|
||||||
|
private Collection<Message> messages = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(name = "user_follows",
|
@JoinTable(name = "user_follows",
|
||||||
joinColumns = @JoinColumn(name = "follower"),
|
joinColumns = @JoinColumn(name = "follower"),
|
||||||
@@ -46,6 +49,12 @@ public class Person implements EntityWithId<String> {
|
|||||||
@ManyToMany(mappedBy = "following")
|
@ManyToMany(mappedBy = "following")
|
||||||
private Collection<Person> followers;
|
private Collection<Person> followers;
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@JoinTable(name = "user_chat",
|
||||||
|
joinColumns = @JoinColumn(name = "user"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "chat"))
|
||||||
|
private Collection<Chat> chats;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return uuid;
|
return uuid;
|
||||||
|
|||||||
Reference in New Issue
Block a user