From 96d25df09d648325009644035832125cf50945d2 Mon Sep 17 00:00:00 2001 From: jedrz Date: Mon, 10 Jul 2017 22:26:57 +0200 Subject: [PATCH 1/3] Addresses issue #6 by changing number of examples to 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 89ddce86e4a92f77a3979fec8b6da845c2080553 Mon Sep 17 00:00:00 2001 From: jedrz Date: Mon, 10 Jul 2017 22:43:31 +0200 Subject: [PATCH 2/3] Addresses bug described in #6 where the total count of the call to action is off --- .../flashy/controllers/IndexController.java | 11 ++++++++--- 1 file changed, 8 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..a15962a 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java @@ -31,10 +31,15 @@ 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 6efdfbb6bf170a273ab9c9a34cc00fbf1461d7f7 Mon Sep 17 00:00:00 2001 From: jedrz Date: Tue, 11 Jul 2017 23:34:52 +0200 Subject: [PATCH 3/3] Fixes #5 by making the cards displayed more standard --- .idea/codeStyleSettings.xml | 9 +++++++++ .idea/misc.xml | 15 +-------------- .idea/modules/flashy_main.iml | 11 ++++++++++- .idea/modules/flashy_test.iml | 7 ++++++- .../flashy/controllers/FlashCardController.java | 2 +- .../flashy/services/FlashCardServiceImpl.java | 11 +++++------ 6 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 .idea/codeStyleSettings.xml diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..5dfbdec --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file 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/.idea/modules/flashy_main.iml b/.idea/modules/flashy_main.iml index 3d7e5d1..49d8bee 100644 --- a/.idea/modules/flashy_main.iml +++ b/.idea/modules/flashy_main.iml @@ -1,6 +1,15 @@ - + + + + + file://$MODULE_DIR$/../../src/main/java/com/teamtreehouse/flashy/App.java + + + + + diff --git a/.idea/modules/flashy_test.iml b/.idea/modules/flashy_test.iml index 3c5b73a..e78e8fe 100644 --- a/.idea/modules/flashy_test.iml +++ b/.idea/modules/flashy_test.iml @@ -1,6 +1,11 @@ - + + + + + + diff --git a/src/main/java/com/teamtreehouse/flashy/controllers/FlashCardController.java b/src/main/java/com/teamtreehouse/flashy/controllers/FlashCardController.java index 44766a0..635ecb8 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/FlashCardController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/FlashCardController.java @@ -24,7 +24,7 @@ public void setFlashCardService(FlashCardService flashCardService) { } private Map getCardCounts(HttpServletRequest req) { - Map cardCounts = (Map) req.getSession().getAttribute("cardCounts"); + Map cardCounts = (Map) req.getSession().getAttribute("cardCounts"); if (cardCounts == null) { cardCounts = new HashMap<>(); req.getSession().setAttribute("cardCounts", cardCounts); diff --git a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java index 5b660e9..4b14bc1 100644 --- a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java +++ b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java @@ -1,8 +1,9 @@ package com.teamtreehouse.flashy.services; +import static java.util.stream.Collectors.toList; + import com.teamtreehouse.flashy.domain.FlashCard; import com.teamtreehouse.flashy.repositories.FlashCardRepository; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -12,8 +13,6 @@ import java.util.Map; import java.util.Random; -import static java.util.stream.Collectors.toList; - @Service public class FlashCardServiceImpl implements FlashCardService { private FlashCardRepository flashCardRepository; @@ -62,10 +61,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); }