CommentController.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.opengroupe.cloud.saas.rest;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestMethod;
  6. import org.springframework.web.bind.annotation.RequestParam;
  7. import org.springframework.web.bind.annotation.ResponseBody;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import com.opengroupe.cloud.saas.domain.Comment;
  10. @RestController
  11. public class CommentController {
  12. private List<Comment> comments = new ArrayList<Comment>();
  13. @RequestMapping("/")
  14. public String index() {
  15. return "Greetings from Spring Boot!";
  16. }
  17. @RequestMapping(value="/api/comments", method=RequestMethod.GET)
  18. public @ResponseBody List<Comment> comments() {
  19. return comments;
  20. }
  21. @RequestMapping(value="/api/comments", method=RequestMethod.POST)
  22. public @ResponseBody List<Comment> comments(
  23. @RequestParam(value="id", required=true) Long id,
  24. @RequestParam(value="author", required=true) String author,
  25. @RequestParam(value="text", required=true) String text) {
  26. comments.add(new Comment(id, author, text));
  27. return comments;
  28. }
  29. }