|
@@ -1,8 +1,8 @@
|
|
|
package com.opengroupe.cloud.saas.rest;
|
|
package com.opengroupe.cloud.saas.rest;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
@@ -10,12 +10,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import com.opengroupe.cloud.saas.domain.Comment;
|
|
import com.opengroupe.cloud.saas.domain.Comment;
|
|
|
|
|
+import com.opengroupe.cloud.saas.service.CommentService;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
public class CommentController {
|
|
public class CommentController {
|
|
|
|
|
|
|
|
- private List<Comment> comments = new ArrayList<Comment>();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommentService service;
|
|
|
|
|
+
|
|
|
@RequestMapping("/")
|
|
@RequestMapping("/")
|
|
|
public String index() {
|
|
public String index() {
|
|
|
return "Greetings from Spring Boot!";
|
|
return "Greetings from Spring Boot!";
|
|
@@ -23,7 +25,7 @@ public class CommentController {
|
|
|
|
|
|
|
|
@RequestMapping(value="/api/comments", method=RequestMethod.GET)
|
|
@RequestMapping(value="/api/comments", method=RequestMethod.GET)
|
|
|
public @ResponseBody List<Comment> comments() {
|
|
public @ResponseBody List<Comment> comments() {
|
|
|
- return comments;
|
|
|
|
|
|
|
+ return service.getAll();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value="/api/comments", method=RequestMethod.POST)
|
|
@RequestMapping(value="/api/comments", method=RequestMethod.POST)
|
|
@@ -31,7 +33,8 @@ public class CommentController {
|
|
|
@RequestParam(value="id", required=true) Long id,
|
|
@RequestParam(value="id", required=true) Long id,
|
|
|
@RequestParam(value="author", required=true) String author,
|
|
@RequestParam(value="author", required=true) String author,
|
|
|
@RequestParam(value="text", required=true) String text) {
|
|
@RequestParam(value="text", required=true) String text) {
|
|
|
- comments.add(new Comment(id, author, text));
|
|
|
|
|
- return comments;
|
|
|
|
|
|
|
+ service.add(new Comment(id, author, text));
|
|
|
|
|
+ return service.getAll();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|