Kaynağa Gözat

updated more service classes

William Simkins 6 yıl önce
ebeveyn
işleme
26cd601ac3

+ 25
- 13
src/main/java/com/tyler/motivateme/service/ForumService.java Dosyayı Görüntüle

@@ -1,29 +1,41 @@
1 1
 package com.tyler.motivateme.service;
2 2
 
3
-import net.anthavio.disquo.api.DisqusApi;
4
-import net.anthavio.disquo.api.DisqusApplicationKeys;
5
-import net.anthavio.disquo.api.response.DisqusPost;
6
-import net.anthavio.disquo.api.response.DisqusResponse;
3
+import com.tyler.motivateme.model.Comment;
4
+import com.tyler.motivateme.repository.CommentRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
7 6
 import org.springframework.stereotype.Service;
8 7
 
8
+import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 
11 11
 @Service
12 12
 public class ForumService {
13
-    DisqusApplicationKeys keys = new DisqusApplicationKeys("...api_key...", "...secret_key...");
14
-    DisqusApi disqus = new DisqusApi(keys);
15
-    private int forumID;
16 13
 
14
+    @Autowired
15
+    private CommentRepository commentRepository;
17 16
 
18
-    public ForumService (int forumID) {
19
-        this.forumID = forumID;
17
+    public List<Comment> allMessages() {
18
+        List<Comment> comments = new ArrayList<>();
19
+        commentRepository.findAll()
20
+                .forEach(comments::add);
21
+        return comments;
20 22
     }
21 23
 
22
-    public void postComment(int forumID){
23
-        disqus.forums();
24
+    public void getAllMessages(Integer id){
25
+        commentRepository.findById(id);
24 26
     }
25 27
 
26
-    public void updateComment(int commentID) {}
27 28
 
28
-    public void deleteComment(int commentID) {}
29
+    public void postComment(Comment forumID){
30
+
31
+        commentRepository.save(forumID);
32
+    }
33
+
34
+    public void updateComment(Comment commentID) {
35
+        commentRepository.save(commentID);
36
+    }
37
+
38
+    public void deleteComment(Comment commentID) {
39
+        commentRepository.delete(commentID);
40
+    }
29 41
 }

+ 26
- 7
src/main/java/com/tyler/motivateme/service/InboxService.java Dosyayı Görüntüle

@@ -1,21 +1,40 @@
1 1
 package com.tyler.motivateme.service;
2 2
 
3
+import com.tyler.motivateme.model.Message;
4
+import com.tyler.motivateme.model.User;
5
+import com.tyler.motivateme.repository.MessageRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
3 7
 import org.springframework.stereotype.Service;
4 8
 
9
+import java.util.ArrayList;
10
+import java.util.List;
11
+
5 12
 @Service
6 13
 public class InboxService {
7
-    private int userID;
8 14
 
9
-    public InboxService(int userID){
10
-        this.userID = userID;
15
+    @Autowired
16
+    private MessageRepository messageRepository;
17
+
18
+    public List<Message> allMessages() {
19
+        List<Message> messages = new ArrayList<>();
20
+        messageRepository.findAll()
21
+                .forEach(messages::add);
22
+        return messages;
11 23
     }
12 24
 
13
-    public void sendMessage(int userID){
25
+    public void getAllMessages(Integer id){
26
+        messageRepository.findById(id);
14 27
     }
15 28
 
16
-    public void viewMessage(int messageID) {}
29
+    public void sendMessage(Message userID){
30
+         messageRepository.save(userID);
31
+    }
17 32
 
18
-    public void updateMessage(int messageID) {}
33
+    public void updateMessage(Message messageID) {
34
+        messageRepository.save(messageID);
35
+    }
19 36
 
20
-    public void deleteMessage(int messageID) {}
37
+    public void deleteMessage(Message messageID) {
38
+        messageRepository.delete(messageID);
39
+    }
21 40
 }