Selaa lähdekoodia

updated controllers and am updating service classes

William Simkins 6 vuotta sitten
vanhempi
commit
7d1b36e74e

BIN
.DS_Store Näytä tiedosto


+ 5
- 3
src/main/java/com/tyler/motivateme/controller/ForumController.java Näytä tiedosto

@@ -3,24 +3,26 @@ package com.tyler.motivateme.controller;
3 3
 import com.tyler.motivateme.model.Topic;
4 4
 import com.tyler.motivateme.service.ForumService;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.web.bind.annotation.CrossOrigin;
6 7
 import org.springframework.web.bind.annotation.RequestMapping;
7 8
 import org.springframework.web.bind.annotation.RequestMethod;
8 9
 import org.springframework.web.bind.annotation.RestController;
9 10
 
10 11
 @RestController
12
+@CrossOrigin
11 13
 public class ForumController {
12 14
     @Autowired
13 15
     ForumService forumService;
14 16
 
15
-    @RequestMapping(method = RequestMethod.POST, value = "/forum")
17
+    @RequestMapping(method = RequestMethod.POST, value = "/forum/{forumid}")
16 18
     public void PostComment(int forumID){
17 19
         forumService.postComment(forumID); }
18 20
 
19
-    @RequestMapping(method = RequestMethod.PUT, value = "/forum/{id}")
21
+    @RequestMapping(method = RequestMethod.PUT, value = "/forum/{commentid}")
20 22
     public void updateComment(int commentID){
21 23
         forumService.updateComment(commentID); }
22 24
 
23
-    @RequestMapping(method = RequestMethod.DELETE, value = "/forum/{id}")
25
+    @RequestMapping(method = RequestMethod.DELETE, value = "/forum/{commentid}")
24 26
     public void deleteComment(int commentID){
25 27
         forumService.deleteComment(commentID); }
26 28
 

+ 6
- 5
src/main/java/com/tyler/motivateme/controller/InboxController.java Näytä tiedosto

@@ -3,30 +3,31 @@ package com.tyler.motivateme.controller;
3 3
 import com.tyler.motivateme.model.Topic;
4 4
 import com.tyler.motivateme.service.InboxService;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.web.bind.annotation.CrossOrigin;
6 7
 import org.springframework.web.bind.annotation.RequestMapping;
7 8
 import org.springframework.web.bind.annotation.RequestMethod;
8 9
 import org.springframework.web.bind.annotation.RestController;
9 10
 
10 11
 @RestController
11
-@RequestMapping("/Inbox")
12
+@CrossOrigin
12 13
 public class InboxController {
13 14
     @Autowired
14 15
     InboxService inboxService;
15 16
 
16
-    @RequestMapping(method = RequestMethod.POST, value = "/inbox")
17
+    @RequestMapping(method = RequestMethod.POST, value = "/inbox/{userid}")
17 18
     public void sendMessage(int userID){
18 19
         inboxService.sendMessage(userID); }
19 20
 
20
-    @RequestMapping(method = RequestMethod.GET, value = "/inbox/{id}")
21
+    @RequestMapping(method = RequestMethod.GET, value = "/inbox/{messageid}")
21 22
     public void viewMessage(int messageID){
22 23
         inboxService.viewMessage(messageID); }
23 24
 
24 25
 
25
-    @RequestMapping(method = RequestMethod.PUT, value = "/inbox/{id}")
26
+    @RequestMapping(method = RequestMethod.PUT, value = "/inbox/{messageid}")
26 27
     public void updateMessage(int messageID){
27 28
         inboxService.updateMessage(messageID); }
28 29
 
29
-    @RequestMapping(method = RequestMethod.DELETE, value = "/inbox/{id}")
30
+    @RequestMapping(method = RequestMethod.DELETE, value = "/inbox/{messageid}")
30 31
     public void deleteMessage(int messageID){
31 32
         inboxService.deleteMessage(messageID); }
32 33
 

+ 33
- 19
src/main/java/com/tyler/motivateme/controller/MainTopicsPageController.java Näytä tiedosto

@@ -1,22 +1,36 @@
1 1
 package com.tyler.motivateme.controller;
2 2
 
3 3
 import com.tyler.motivateme.model.Topic;
4
-import com.tyler.motivateme.service.MainTopicsPageService;
5
-import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.web.bind.annotation.RequestMapping;
7
-import org.springframework.web.bind.annotation.RequestMethod;
8
-import org.springframework.web.bind.annotation.RestController;
9
-
10
-import java.util.List;
11
-
12
-@RestController
13
-public class MainTopicsPageController {
14
-    @Autowired
15
-    MainTopicsPageService mainTopicsPageService;
16
-
17
-    @RequestMapping(method = RequestMethod.GET, value = "/topics")
18
-    public List<Topic> allTopics() {
19
-
20
-        return mainTopicsPageService.allTopics();
21
-    }
22
-}
4
+//import com.tyler.motivateme.service.MainTopicsPageService;
5
+//import org.springframework.beans.factory.annotation.Autowired;
6
+//import org.springframework.web.bind.annotation.CrossOrigin;
7
+//import org.springframework.web.bind.annotation.RequestMapping;
8
+//import org.springframework.web.bind.annotation.RequestMethod;
9
+//import org.springframework.web.bind.annotation.RestController;
10
+//
11
+//import java.util.List;
12
+//
13
+//@RestController
14
+//@CrossOrigin
15
+//public class MainTopicsPageController {
16
+//    @Autowired
17
+//    MainTopicsPageService mainTopicsPageService;
18
+//
19
+//    @RequestMapping(method = RequestMethod.GET, value = "/topics")
20
+//    public List<Topic> allTopics() {
21
+//
22
+//        return mainTopicsPageService.allTopics();
23
+//    }
24
+//
25
+//    @RequestMapping(method = RequestMethod.POST, value = "/topics/{id}")
26
+//    public void add(Topic topic){
27
+//        mainTopicsPageService.add(topic); }
28
+//
29
+//    @RequestMapping(method = RequestMethod.PUT, value = "/topics/{id}")
30
+//    public void update(int topicIndex, Topic newTopic){
31
+//        mainTopicsPageService.update(topicIndex, newTopic); }
32
+//
33
+//    @RequestMapping(method = RequestMethod.DELETE, value = "/topics/{id}")
34
+//    public void delete(Topic topic){
35
+//        mainTopicsPageService.delete(topic); }
36
+//}

+ 48
- 0
src/main/java/com/tyler/motivateme/controller/TopicController.java Näytä tiedosto

@@ -0,0 +1,48 @@
1
+package com.tyler.motivateme.controller;
2
+
3
+import com.tyler.motivateme.repository.TopicRepository;
4
+import com.tyler.motivateme.service.TopicCreatorService;
5
+import com.tyler.motivateme.model.Topic;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.web.bind.annotation.*;
8
+
9
+import java.util.List;
10
+
11
+@RestController
12
+@CrossOrigin
13
+public class TopicController {
14
+
15
+//    @Autowired
16
+//    private TopicCreatorService topicCreatorService;
17
+
18
+    @Autowired
19
+    private TopicRepository topicRepository;
20
+
21
+    @RequestMapping(method = RequestMethod.GET, value="/topics")
22
+    public Iterable<Topic> allTopics() {
23
+        return topicRepository.findAll();
24
+    }
25
+
26
+
27
+
28
+//    @RequestMapping(method = RequestMethod.GET, value = "/CreateTopic")
29
+//    public List<Topic> allTopics() {
30
+//
31
+//        return topicCreatorService.allTopics();
32
+//    }
33
+//
34
+//    @RequestMapping(method = RequestMethod.POST, value = "/CreateTopic")
35
+//    public void add(Topic topic){
36
+//        topicCreatorService.add(topic); }
37
+//
38
+//    @RequestMapping(method = RequestMethod.PUT, value = "/CreateTopic/{id}")
39
+//    public void update(int topicIndex, Topic newTopic){
40
+//        topicCreatorService.update(topicIndex, newTopic); }
41
+//
42
+//    @RequestMapping(method = RequestMethod.DELETE, value = "/CreateTopic/{id}")
43
+//    public void delete(Topic topic){
44
+//        topicCreatorService.delete(topic); }
45
+
46
+
47
+
48
+}

+ 0
- 39
src/main/java/com/tyler/motivateme/controller/TopicCreatorController.java Näytä tiedosto

@@ -1,39 +0,0 @@
1
-package com.tyler.motivateme.controller;
2
-
3
-import com.tyler.motivateme.service.TopicCreatorService;
4
-import com.tyler.motivateme.model.Topic;
5
-import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.web.bind.annotation.PostMapping;
7
-import org.springframework.web.bind.annotation.RequestMapping;
8
-import org.springframework.web.bind.annotation.RequestMethod;
9
-import org.springframework.web.bind.annotation.RestController;
10
-
11
-import java.util.List;
12
-
13
-@RestController
14
-public class TopicCreatorController {
15
-
16
-    @Autowired
17
-    private TopicCreatorService topicCreatorService;
18
-
19
-    @RequestMapping(method = RequestMethod.GET, value = "/CreateTopic")
20
-    public List<Topic> allTopics() {
21
-
22
-        return topicCreatorService.allTopics();
23
-    }
24
-
25
-    @RequestMapping(method = RequestMethod.POST, value = "/CreateTopic")
26
-    public void add(Topic topic){
27
-        topicCreatorService.add(topic); }
28
-
29
-    @RequestMapping(method = RequestMethod.PUT, value = "/CreateTopic/{id}")
30
-    public void update(Topic topic){
31
-        topicCreatorService.update(topic); }
32
-
33
-    @RequestMapping(method = RequestMethod.DELETE, value = "/CreateTopic/{id}")
34
-    public void delete(Topic topic){
35
-        topicCreatorService.delete(topic); }
36
-
37
-
38
-
39
-}

+ 36
- 24
src/main/java/com/tyler/motivateme/controller/TopicInfoPageController.java Näytä tiedosto

@@ -1,24 +1,36 @@
1
-package com.tyler.motivateme.controller;
2
-
3
-import com.tyler.motivateme.service.TopicInfoPageService;
4
-import org.springframework.beans.factory.annotation.Autowired;
5
-import org.springframework.web.bind.annotation.RequestMapping;
6
-import org.springframework.web.bind.annotation.RestController;
7
-
8
-@RestController
9
-public class TopicInfoPageController {
10
-
11
-    @Autowired
12
-    private TopicInfoPageService topicInfoPageService;
13
-
14
-    public void getTopicName() {}
15
-
16
-    public void getDescription() {
17
-
18
-    }
19
-
20
-    public void getAdviceAndStrategies() {
21
-
22
-    }
23
-
24
-}
1
+//package com.tyler.motivateme.controller;
2
+//
3
+//import com.tyler.motivateme.service.TopicInfoPageService;
4
+//import org.springframework.beans.factory.annotation.Autowired;
5
+//import org.springframework.web.bind.annotation.CrossOrigin;
6
+//import org.springframework.web.bind.annotation.RequestMapping;
7
+//import org.springframework.web.bind.annotation.RequestMethod;
8
+//import org.springframework.web.bind.annotation.RestController;
9
+//
10
+//@RestController
11
+//@CrossOrigin
12
+//public class TopicInfoPageController {
13
+//
14
+//    @Autowired
15
+//    private TopicInfoPageService topicInfoPageService;
16
+//
17
+//    @RequestMapping(method = RequestMethod.GET, value = "/TopicInfo/{topicid}")
18
+//    public void getTopicName() {}
19
+//
20
+//    @RequestMapping(method = RequestMethod.GET, value = "/TopicInfo/{descriptionid}")
21
+//    public void getDescription() {
22
+//
23
+//    }
24
+//
25
+//    @RequestMapping(method = RequestMethod.GET, value = "/TopicInfo/{ASid}")
26
+//    public void getAdviceAndStrategies() {
27
+//
28
+//    }
29
+//
30
+//    @RequestMapping(method = RequestMethod.POST, value = "/TopicInfo/{descriptionid}")
31
+//    public void updateDescription(){ }
32
+//
33
+//    @RequestMapping(method = RequestMethod.POST, value = "/TopicInfo/{ASid}")
34
+//    public void updateAdviceAndStrategies(){}
35
+//
36
+//}

+ 1
- 1
src/main/java/com/tyler/motivateme/model/Message.java Näytä tiedosto

@@ -10,4 +10,4 @@ public class Message {
10 10
     @Id
11 11
     @GeneratedValue(strategy = GenerationType.AUTO)
12 12
     private int messageID;
13
-}
13
+}

+ 1
- 1
src/main/java/com/tyler/motivateme/model/Topic.java Näytä tiedosto

@@ -16,7 +16,7 @@ public class Topic {
16 16
     private String adviceAndStrategies;
17 17
 
18 18
 
19
-    public Topic(int id, String name) {
19
+    public Topic(int id, String name, String description, String adviceAndStrategies) {
20 20
         this.id = id;
21 21
         this.name = name;
22 22
         this.description = description;

+ 16
- 0
src/main/java/com/tyler/motivateme/model/TopicMessage.java Näytä tiedosto

@@ -0,0 +1,16 @@
1
+package com.tyler.motivateme.model;
2
+
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.GenerationType;
6
+import javax.persistence.Id;
7
+
8
+@Entity
9
+public class TopicMessage {
10
+    @Id
11
+    @GeneratedValue(strategy = GenerationType.AUTO)
12
+
13
+    private String user_id;
14
+    private String topic_id;
15
+    private int date;
16
+}

+ 2
- 0
src/main/java/com/tyler/motivateme/repository/CommentRepository.java Näytä tiedosto

@@ -1,9 +1,11 @@
1 1
 package com.tyler.motivateme.repository;
2 2
 
3 3
 import com.tyler.motivateme.model.Comment;
4
+import org.springframework.data.jpa.repository.Query;
4 5
 import org.springframework.data.repository.CrudRepository;
5 6
 import org.springframework.stereotype.Repository;
6 7
 
7 8
 @Repository
8 9
 public interface CommentRepository extends CrudRepository<Comment, Integer> {
10
+
9 11
 }

+ 10
- 0
src/main/java/com/tyler/motivateme/repository/TopicMessageRepository.java Näytä tiedosto

@@ -0,0 +1,10 @@
1
+package com.tyler.motivateme.repository;
2
+
3
+import com.tyler.motivateme.model.Message;
4
+import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.stereotype.Repository;
6
+
7
+@Repository
8
+public interface TopicMessageRepository extends CrudRepository<Message, Integer> {
9
+
10
+}

+ 15
- 5
src/main/java/com/tyler/motivateme/service/ForumService.java Näytä tiedosto

@@ -1,16 +1,26 @@
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 7
 import org.springframework.stereotype.Service;
4 8
 
9
+import java.util.List;
10
+
5 11
 @Service
6 12
 public class ForumService {
7
-    private Integer forumID;
8
-//
9
-//    public ForumService(Integer forumID) {
10
-//        this.forumID = forumID;
11
-//    }
13
+    DisqusApplicationKeys keys = new DisqusApplicationKeys("...api_key...", "...secret_key...");
14
+    DisqusApi disqus = new DisqusApi(keys);
15
+    private int forumID;
16
+
17
+
18
+    public ForumService (int forumID) {
19
+        this.forumID = forumID;
20
+    }
12 21
 
13 22
     public void postComment(int forumID){
23
+        disqus.forums();
14 24
     }
15 25
 
16 26
     public void updateComment(int commentID) {}

+ 3
- 3
src/main/java/com/tyler/motivateme/service/InboxService.java Näytä tiedosto

@@ -6,9 +6,9 @@ import org.springframework.stereotype.Service;
6 6
 public class InboxService {
7 7
     private int userID;
8 8
 
9
-//    public InboxService(int userID){
10
-//        this.userID = userID;
11
-//    }
9
+    public InboxService(int userID){
10
+        this.userID = userID;
11
+    }
12 12
 
13 13
     public void sendMessage(int userID){
14 14
     }

+ 20
- 5
src/main/java/com/tyler/motivateme/service/MainTopicsPageService.java Näytä tiedosto

@@ -1,6 +1,9 @@
1 1
 package com.tyler.motivateme.service;
2 2
 
3 3
 import com.tyler.motivateme.model.Topic;
4
+import com.tyler.motivateme.repository.TopicRepository;
5
+import org.apache.el.stream.Stream;
6
+import org.springframework.beans.factory.annotation.Autowired;
4 7
 import org.springframework.context.annotation.Bean;
5 8
 import org.springframework.stereotype.Service;
6 9
 
@@ -9,15 +12,27 @@ import java.util.List;
9 12
 
10 13
 @Service
11 14
 public class MainTopicsPageService {
12
-    List<Topic> topics;
13 15
 
14
-    public MainTopicsPageService(){
15
-        this.topics = new ArrayList<>();
16
-    }
16
+    @Autowired
17
+    private TopicRepository topicRepository;
17 18
 
18 19
     public List<Topic> allTopics() {
20
+        List<Topic> allTopics = new ArrayList<>();
21
+        topicRepository.findAll()
22
+                .forEach(allTopics::add);
23
+        return allTopics;
24
+    }
25
+
26
+    public void getAllTopics(Integer id){
27
+        topicRepository.findById(id);
28
+    }
19 29
 
20
-        return topics;
30
+    public void add(Topic topic) {
31
+        topicRepository.save(topic);
21 32
     }
22 33
 
34
+    public void update(Topic newTopic) { topicRepository.save(newTopic);}
35
+
36
+    public void delete(Integer id) { topicRepository.deleteById(id); }
37
+
23 38
 }

+ 2
- 2
src/main/java/com/tyler/motivateme/service/TopicCreatorService.java Näytä tiedosto

@@ -10,7 +10,7 @@ import java.util.List;
10 10
 @Service
11 11
 public class TopicCreatorService {
12 12
 
13
-    private List<Topic> topics = new ArrayList<Topic>(Arrays.asList(new Topic(1, "Quit drinking"), new Topic(2, "Quit Smoking"), new Topic(3, "Eat healthier")));
13
+    private List<Topic> topics = new ArrayList<>();
14 14
     private String description;
15 15
     private String adviceAndStrategies;
16 16
 
@@ -23,7 +23,7 @@ public class TopicCreatorService {
23 23
         topics.add(topic);
24 24
     }
25 25
 
26
-    public void update(Topic topic) {}
26
+    public void update(int topicIndex, Topic newTopic) { topics.set(topicIndex, newTopic);}
27 27
 
28 28
     public void delete(Topic topic) { topics.remove(topic); }
29 29
 }

+ 25
- 5
src/main/java/com/tyler/motivateme/service/TopicInfoPageService.java Näytä tiedosto

@@ -5,13 +5,33 @@ import org.springframework.stereotype.Service;
5 5
 @Service
6 6
 public class TopicInfoPageService {
7 7
 
8
-    public String getTopicName() {return null;}
8
+    private String topicName;
9
+    private String description;
10
+    private String adviceAndStrategies;
9 11
 
10
-    public String getDescription() {
11
-        return null;
12
+    public void setTopicName(String topicName) {
13
+        this.topicName = topicName;
12 14
     }
13 15
 
14
-    public String getAdviceAndStrategies() {
15
-        return null;
16
+    public void setDescription(String description) {
17
+        this.description = description;
16 18
     }
19
+
20
+    public void setAdviceAndStrategies(String adviceAndStrategies) {
21
+        this.adviceAndStrategies = adviceAndStrategies;
22
+    }
23
+
24
+    public String getTopicName() { return topicName;}
25
+
26
+    public String getDescription() { return description;
27
+
28
+    }
29
+
30
+    public String getAdviceAndStrategies() { return adviceAndStrategies;
31
+
32
+    }
33
+
34
+    public void updateDescription(){ }
35
+
36
+    public void updateAdviceAndStrategies(){}
17 37
 }

+ 1
- 1
src/main/resources/application.properties Näytä tiedosto

@@ -1,4 +1,4 @@
1
-spring.jpa.hibernate.ddl-auto=create-drop
1
+spring.jpa.hibernate.ddl-auto=update
2 2
 spring.datasource.url=jdbc:mysql://localhost:3306/motivateme?useSSL=false
3 3
 spring.datasource.username=root
4 4
 spring.datasource.password=password

+ 9
- 8
src/test/java/service/TopicCreatorServiceTest.java Näytä tiedosto

@@ -24,7 +24,7 @@ public class TopicCreatorServiceTest {
24 24
 
25 25
     @Test
26 26
     public void testAllTopics_AreInList(){
27
-        List expected = new ArrayList<>(Arrays.asList(new Topic(1, "Quit drinking"), new Topic(2, "Quit Smoking"), new Topic(3, "Eat healthier")));
27
+        List expected = new ArrayList<>(Arrays.asList());
28 28
         List actual = tcs.allTopics();
29 29
         assertEquals(expected, actual);
30 30
     }
@@ -34,13 +34,13 @@ public class TopicCreatorServiceTest {
34 34
     public void testConstruction(){
35 35
         List<Topic> topics = tcs.allTopics();
36 36
 
37
-        assertEquals(topics.size(), 3);
38
-        assertTrue(topics.contains(new Topic(1, "Quit drinking")));
37
+        assertEquals(topics.size(), 0);
38
+        assertTrue(topics.contains(0));
39 39
     }
40 40
 
41 41
     @Test
42 42
     public void testAddTopic_ToAllTopics(){
43
-        Topic topic = new Topic(4, "working out");
43
+        Topic topic = new Topic();
44 44
         tcs.add(topic);
45 45
 
46 46
         List<Topic> topics = tcs.allTopics();
@@ -50,17 +50,18 @@ public class TopicCreatorServiceTest {
50 50
 
51 51
     @Test
52 52
     public void testUpdateTopic_InAllTopics(){
53
-        Topic topic = new Topic(4, "working out");
54
-        tcs.update(topic);
53
+        int topicIndex = 2;
54
+        Topic newTopic = new Topic();
55
+        tcs.update(topicIndex, newTopic);
55 56
 
56 57
         List<Topic> topics = tcs.allTopics();
57 58
 
58
-        assertFalse(topics.contains(topic));
59
+        assertTrue(topics.contains(newTopic));
59 60
     }
60 61
 
61 62
     @Test
62 63
     public void testDeleteTopic_FromAllTopics(){
63
-        Topic topic = new Topic(2, "Quit Smoking");
64
+        Topic topic = new Topic();
64 65
         tcs.delete(topic);
65 66
 
66 67
         List<Topic> topics = tcs.allTopics();

+ 1
- 0
src/test/java/service/TopicInfoPageServiceTest.java Näytä tiedosto

@@ -11,6 +11,7 @@ public class TopicInfoPageServiceTest {
11 11
 
12 12
     @Test
13 13
     public void testGetDescription() {
14
+
14 15
     }
15 16
 
16 17
     @Test