2 次程式碼提交

作者 SHA1 備註 提交日期
  Chad b8d0c1d8d8 merged dev 6 年之前
  Chad 4a6aefe826 added Chat classes 6 年之前

二進制
.DS_Store 查看文件


+ 53
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/Chat.java 查看文件

@@ -0,0 +1,53 @@
1
+package ZipTeamOrange.chat;
2
+
3
+import ZipTeamOrange.message.Message;
4
+import ZipTeamOrange.user.User;
5
+
6
+import javax.persistence.*;
7
+import java.util.Set;
8
+
9
+@Entity
10
+public class Chat {
11
+
12
+    @Id
13
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
14
+    private Long id;
15
+    private String name;
16
+
17
+    @OneToMany
18
+    private Set<Message> messages;
19
+
20
+    @ManyToMany
21
+    private Set<User> users;
22
+
23
+    public Chat(String name, Set<User> users) {
24
+        this.name = name;
25
+        this.users = users;
26
+    }
27
+
28
+    public Chat(){}
29
+
30
+    public Long getId() {
31
+        return id;
32
+    }
33
+
34
+    public void setId(Long id) {
35
+        this.id = id;
36
+    }
37
+
38
+    public String getName() {
39
+        return name;
40
+    }
41
+
42
+    public void setName(String name) {
43
+        this.name = name;
44
+    }
45
+
46
+    public Set<User> getUsers() {
47
+        return users;
48
+    }
49
+
50
+    public void setUsers(Set<User> users) {
51
+        this.users = users;
52
+    }
53
+}

+ 28
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/ChatController.java 查看文件

@@ -0,0 +1,28 @@
1
+package ZipTeamOrange.chat;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.stereotype.Controller;
5
+import org.springframework.web.bind.annotation.*;
6
+
7
+@Controller
8
+@RequestMapping(path = "/chat")
9
+public class ChatController {
10
+
11
+    @Autowired
12
+    private ChatRepository chatRepository;
13
+
14
+    @PostMapping(path="/add")
15
+    @CrossOrigin(origins = {"http://localhost:8103"})
16
+    public @ResponseBody
17
+    String addNewChat(@RequestBody Chat chat){
18
+        chatRepository.save(chat);
19
+        return  "saved";
20
+    }
21
+
22
+    @GetMapping(path="/all")
23
+    public @ResponseBody Iterable<Chat> getAllChat(){
24
+        //this returns a JSON or XML with chats
25
+        return chatRepository.findAll();
26
+    }
27
+
28
+}

+ 6
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/ChatRepository.java 查看文件

@@ -0,0 +1,6 @@
1
+package ZipTeamOrange.chat;
2
+
3
+import org.springframework.data.jpa.repository.JpaRepository;
4
+
5
+public interface ChatRepository extends JpaRepository<Chat, Long> {
6
+}