diff --git a/src/main/java/com/pluralsight/blog/BlogController.java b/src/main/java/com/pluralsight/blog/BlogController.java index 2ebd92fb..49778087 100644 --- a/src/main/java/com/pluralsight/blog/BlogController.java +++ b/src/main/java/com/pluralsight/blog/BlogController.java @@ -1,8 +1,25 @@ package com.pluralsight.blog; +import com.pluralsight.blog.data.PostRepository; +import com.pluralsight.blog.model.Post; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.List; @Controller public class BlogController { + private PostRepository postRepository; + + public BlogController(PostRepository postRepository) { + this.postRepository = postRepository; + } + @RequestMapping("/") + public String listPosts(ModelMap modelMap) { + List posts = postRepository.getAllPosts(); + modelMap.put("posts", posts); + return "home"; + } } diff --git a/src/main/java/com/pluralsight/blog/data/PostRepository.java b/src/main/java/com/pluralsight/blog/data/PostRepository.java index 7842767d..3f04d0e4 100644 --- a/src/main/java/com/pluralsight/blog/data/PostRepository.java +++ b/src/main/java/com/pluralsight/blog/data/PostRepository.java @@ -2,13 +2,52 @@ import com.pluralsight.blog.model.Post; import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; import java.util.List; @Component public class PostRepository { + private final List ALL_POSTS = new ArrayList<>(Arrays.asList( + new Post(1l, "Earbuds", + "You have got to try these in your ears. So tiny and can even block the sounds of screaming toddlers if you so desire.", + "You have got to try these in your ears. So tiny and can even block the sounds of screaming toddlers if you so desire.", + "Sarah Holderness", new Date("10/31/2019")), + new Post(2l, "Smart Speakers", + "Smart speakers listen to you all right. Sometimes they get a little snippy but will still order your favorite takeout.", + "Smart speakers listen to you all right. Sometimes they get a little snippy but will still order your favorite takeout.", + "Sarah Holderness", new Date()), + new Post(3l, "Device Charger", + "We all do a little too much scrolling in lieu of human interaction. This charger will keep you isolated.", + "We all do a little too much scrolling in lieu of human interaction. This charger will keep you isolated.", + "Sarah Holderness", new Date()), + new Post(4l, "Smart Home Lock", + "Want to play tricks on your teenager? This smart home lock will lock them out when they act like they run the house.", + "Want to play tricks on your teenager? This smart home lock will lock them out when they act like they run the house.", + "Sarah Holderness", new Date("10/31/2019")), + new Post(5l, "Smart Instant Pot", + "This Instant Pot can do your shopping for you. When it gets home it will also put your meal together.", + "This Instant Pot can do your shopping for you. When it gets home it will also put your meal together.", + "Sarah Holderness", new Date("10/31/2019")), + new Post(6l, "Mobile Tripod", + "Best gift for that older adult in your life who cannot keep their face in the FaceTime window.", + "Best gift for that older adult in your life who cannot keep their face in the FaceTime window.", + "Sarah Holderness", new Date("10/31/2019")), + new Post(7l, "Travel Keyboard", + "You never know when inspiration for your latest novel will strike. Meet the perfect travel keyboard for your random thoughts.", + "You never know when inspiration for your latest novel will strike. Meet the perfect travel keyboard for your random thoughts.", + "Sarah Holderness", new Date("10/31/2019")), + new Post(8l, "SD Card Reader", + "When a stranger passes us a top secret SD card the adventure begins. Jason Bourne says, \"Hi\".", + "When a stranger passes us a top secret SD card the adventure begins. Jason Bourne says, \"Hi\".", + "Sarah Holderness", new Date("10/31/2019")) + )); + public List getAllPosts() { - return null; + return ALL_POSTS; } public Post findById(Long id) { diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 566549bd..9928344b 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -1,10 +1,12 @@ - + Title - +
+

+
\ No newline at end of file