Pārlūkot izejas kodu

Updated Chat class

JaseG256 6 gadus atpakaļ
vecāks
revīzija
c928a5e936

+ 33
- 17
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Chat.java Parādīt failu

@@ -1,30 +1,38 @@
1 1
 package ZipTeamOrange.model;
2 2
 
3
+import ZipTeamOrange.model.Audit.UserDateAudit;
3 4
 import ZipTeamOrange.model.Message;
4 5
 import ZipTeamOrange.model.User;
5 6
 import javax.persistence.*;
7
+import javax.validation.constraints.NotBlank;
6 8
 import java.util.Set;
7 9
 
8 10
 @Entity
9
-public class Chat {
11
+@Table(name = "chats")
12
+public class Chat extends UserDateAudit {
10 13
 
11 14
     @Id
12 15
     @GeneratedValue(strategy = GenerationType.IDENTITY)
13 16
     private Long id;
14
-    private String name;
15 17
 
16
-    @OneToMany(mappedBy = "chat")
18
+    @NotBlank
19
+    private String topic;
20
+
21
+    @OneToMany(mappedBy = "chat",
22
+    cascade = CascadeType.ALL,
23
+    fetch = FetchType.EAGER,
24
+    orphanRemoval = true)
17 25
     private Set<Message> messages;
18 26
 
19
-    @ManyToMany(mappedBy = "chat")
20
-    private Set<User> users;
27
+//    @ManyToMany(mappedBy = "chat")
28
+//    private Set<User> users;
21 29
 
22
-    public Chat(String name, Set<User> users) {
23
-        this.name = name;
24
-        this.users = users;
30
+    public Chat(String topic, Set<Message> messages) {
31
+        this.topic = topic;
32
+        this.messages = messages;
25 33
     }
26 34
 
27
-    public Chat(){}
35
+    public Chat() { }
28 36
 
29 37
     public Long getId() {
30 38
         return id;
@@ -34,19 +42,27 @@ public class Chat {
34 42
         this.id = id;
35 43
     }
36 44
 
37
-    public String getName() {
38
-        return name;
45
+    public String getTopic() {
46
+        return topic;
39 47
     }
40 48
 
41
-    public void setName(String name) {
42
-        this.name = name;
49
+    public void setTopic(String topic) {
50
+        this.topic = topic;
43 51
     }
44 52
 
45
-    public Set<User> getUsers() {
46
-        return users;
53
+    public Set<Message> getMessages() {
54
+        return messages;
47 55
     }
48 56
 
49
-    public void setUsers(Set<User> users) {
50
-        this.users = users;
57
+    public void setMessages(Set<Message> messages) {
58
+        this.messages = messages;
51 59
     }
60
+
61
+    //    public Set<User> getUsers() {
62
+//        return users;
63
+//    }
64
+//
65
+//    public void setUsers(Set<User> users) {
66
+//        this.users = users;
67
+//    }
52 68
 }

+ 54
- 52
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Message.java Parādīt failu

@@ -1,52 +1,54 @@
1
-//package ZipTeamOrange.model;
2
-//
3
-//import javax.persistence.*;
4
-//
5
-//@Entity
6
-//public class Message {
7
-//
8
-//    @Id
9
-//    @GeneratedValue(strategy = GenerationType.IDENTITY)
10
-//    private long id;
11
-//    String message;
12
-//    @ManyToOne
13
-//    @JoinColumn(name="user_id")
14
-//    User user;
15
-//
16
-//    @ManyToOne
17
-//    @JoinColumn(name = "chat_id")
18
-//    private Chat chat;
19
-//
20
-//
21
-//    public Message(String message) {
22
-//        this.message = message;
23
-//        //this.user = user;
24
-//    }
25
-//
26
-//
27
-//    public Message(){}
28
-//
29
-//    public long getId() {
30
-//        return id;
31
-//    }
32
-//
33
-//    public void setId(long id) {
34
-//        this.id = id;
35
-//    }
36
-//
37
-//    public String getMessage() {
38
-//        return message;
39
-//    }
40
-//
41
-//    public void setMessage(String message) {
42
-//        this.message = message;
43
-//    }
44
-//
45
-//    public User getUser() {
46
-//        return user;
47
-//    }
48
-//
49
-//    public void setUser(User user) {
50
-//        this.user = user;
51
-//    }
52
-//}
1
+package ZipTeamOrange.model;
2
+
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Message {
7
+
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
10
+    private long id;
11
+
12
+    String message;
13
+
14
+    @ManyToOne
15
+    @JoinColumn(name="user_id")
16
+    User user;
17
+
18
+    @ManyToOne
19
+    @JoinColumn(name = "chat_id")
20
+    private Chat chat;
21
+
22
+
23
+    public Message(String message) {
24
+        this.message = message;
25
+        //this.user = user;
26
+    }
27
+
28
+
29
+    public Message(){}
30
+
31
+    public long getId() {
32
+        return id;
33
+    }
34
+
35
+    public void setId(long id) {
36
+        this.id = id;
37
+    }
38
+
39
+    public String getMessage() {
40
+        return message;
41
+    }
42
+
43
+    public void setMessage(String message) {
44
+        this.message = message;
45
+    }
46
+
47
+    public User getUser() {
48
+        return user;
49
+    }
50
+
51
+    public void setUser(User user) {
52
+        this.user = user;
53
+    }
54
+}