From 43ce7eaddba553830a7f9588c3f5a396432c68bb Mon Sep 17 00:00:00 2001 From: wulfey Date: Sun, 11 Dec 2016 22:51:29 -0800 Subject: [PATCH 1/3] Address issue #6 by changing the number of exampels to show 3 and add constant 3 --- .../com/teamtreehouse/flashy/controllers/IndexController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java index f127754..6ebbcac 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java @@ -12,6 +12,7 @@ @Controller public class IndexController { + public static final int AMOUNT_TO_SHOW = 3; private FlashCardService flashCardService; @Autowired @@ -22,7 +23,7 @@ public void setFlashCardService(FlashCardService flashCardService) { @RequestMapping("/") public String index(Model model) { StringBuilder ctaBuilder = new StringBuilder(); - List cards = flashCardService.getRandomFlashCards(5); + List cards = flashCardService.getRandomFlashCards(AMOUNT_TO_SHOW); ctaBuilder.append("Refresh your memory about "); for (FlashCard card : cards) { ctaBuilder.append(card.getTerm()); From d430b7ecc181ffd9979387bbcb59eed6837ca86f Mon Sep 17 00:00:00 2001 From: wulfey Date: Sun, 11 Dec 2016 23:01:15 -0800 Subject: [PATCH 2/3] addresses bug described in #6 where total count in the call to action was off --- .../flashy/controllers/IndexController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java index 6ebbcac..f5f16a3 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java @@ -31,10 +31,13 @@ public String index(Model model) { ctaBuilder.append(", "); } } - ctaBuilder.append(" and "); Long totalCount = flashCardService.getCurrentCount(); - ctaBuilder.append(totalCount); - ctaBuilder.append(" more"); + if (totalCount > AMOUNT_TO_SHOW){ + ctaBuilder.append(" and "); + ctaBuilder.append(totalCount - AMOUNT_TO_SHOW); + ctaBuilder.append(" more"); + } + model.addAttribute("cta", ctaBuilder.toString()); model.addAttribute("flashCardCount", totalCount); return "index"; From c6068aae7d08cb738deb51d6f06056f07c417941 Mon Sep 17 00:00:00 2001 From: wulfey Date: Mon, 12 Dec 2016 17:03:34 -0800 Subject: [PATCH 3/3] address bogus #6 counting gets bogus after every card has been viewed once, making cards displayed more standard --- .idea/misc.xml | 15 +-------------- .../flashy/services/FlashCardServiceImpl.java | 6 +++--- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 164b970..d5d79e0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,19 +1,6 @@ - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java index 5b660e9..4a0034b 100644 --- a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java +++ b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java @@ -62,10 +62,10 @@ public FlashCard getNextFlashCardBasedOnViews(Map idToViewCounts) { continue; } Long lowestScore = idToViewCounts.get(leastViewedId); - if (entry.getValue() >= lowestScore) { - break; + if (entry.getValue() < lowestScore) { + + leastViewedId = entry.getKey(); } - leastViewedId = entry.getKey(); } return flashCardRepository.findOne(leastViewedId); }