From 670815a91c76c93c042e2b8018b35b4088c66bde Mon Sep 17 00:00:00 2001 From: sarah Date: Fri, 22 Nov 2019 12:53:58 -0500 Subject: [PATCH 1/2] Module 1 Solution --- src/main/java/com/pluralsight/blog/BlogController.java | 7 +++++++ src/main/resources/templates/home.html | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pluralsight/blog/BlogController.java b/src/main/java/com/pluralsight/blog/BlogController.java index 2ebd92fb..ecec6132 100644 --- a/src/main/java/com/pluralsight/blog/BlogController.java +++ b/src/main/java/com/pluralsight/blog/BlogController.java @@ -1,8 +1,15 @@ package com.pluralsight.blog; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; @Controller public class BlogController { + @RequestMapping("/") + public String listPosts(ModelMap modelMap) { + modelMap.put("title", "Blog Post 1"); + return "home"; + } } diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 566549bd..a14a4f83 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -1,10 +1,10 @@ - + Title - +

\ No newline at end of file From 6ac9e43b5f3046b880720c3ff6a65bcf7119d30e Mon Sep 17 00:00:00 2001 From: sarah Date: Fri, 22 Nov 2019 13:02:08 -0500 Subject: [PATCH 2/2] Module 2 Solution --- .../com/pluralsight/blog/BlogController.java | 12 +++++- .../pluralsight/blog/data/PostRepository.java | 41 ++++++++++++++++++- src/main/resources/templates/home.html | 4 +- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/pluralsight/blog/BlogController.java b/src/main/java/com/pluralsight/blog/BlogController.java index ecec6132..49778087 100644 --- a/src/main/java/com/pluralsight/blog/BlogController.java +++ b/src/main/java/com/pluralsight/blog/BlogController.java @@ -1,15 +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) { - modelMap.put("title", "Blog Post 1"); + 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 a14a4f83..9928344b 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -5,6 +5,8 @@ Title -

+
+

+
\ No newline at end of file