From 31b94b26bf6a9af173f9134459f7af44632df9f3 Mon Sep 17 00:00:00 2001 From: Iver Band Date: Sun, 26 Feb 2017 13:04:13 -0800 Subject: [PATCH 1/4] Added and applied Google Style --- .idea/codeStyleSettings.xml | 464 ++++++++++++++++++++++++++++++++++++ .idea/dbnavigator.xml | 450 ++++++++++++++++++++++++++++++++++ 2 files changed, 914 insertions(+) create mode 100644 .idea/codeStyleSettings.xml create mode 100644 .idea/dbnavigator.xml diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..0f15009 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,464 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..fb80ce3 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,450 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 3f18f87d5585e0bcdbe53eda151aff9b3621d7bd Mon Sep 17 00:00:00 2001 From: Iver Band Date: Mon, 27 Feb 2017 21:17:55 -0800 Subject: [PATCH 2/4] Addresses issue #9 by changing number of examples on homepage from 5 to 3 --- .../com/teamtreehouse/flashy/controllers/IndexController.java | 4 +++- 1 file changed, 3 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..e91d458 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java @@ -12,6 +12,8 @@ @Controller public class IndexController { + + public static final int AMOUNT_TO_SHOW = 3; private FlashCardService flashCardService; @Autowired @@ -22,7 +24,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 3dcba7c634cb3b2ef278afcec6b622c346b84584 Mon Sep 17 00:00:00 2001 From: Iver Band Date: Mon, 27 Feb 2017 21:43:59 -0800 Subject: [PATCH 3/4] Addresses issue #9 by fixing the inaccurate count of available cards in the call to action --- .idea/misc.xml | 15 +-------------- .../flashy/controllers/IndexController.java | 9 +++++---- 2 files changed, 6 insertions(+), 18 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/controllers/IndexController.java b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java index e91d458..8f8680d 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java @@ -32,13 +32,14 @@ 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 d25a111e0766ab7d9e8d4da403189672764150ca Mon Sep 17 00:00:00 2001 From: Iver Band Date: Sat, 4 Mar 2017 21:53:54 -0800 Subject: [PATCH 4/4] Addresses issue #8 by fixing the bogus counting of card views --- .../flashy/controllers/IndexController.java | 6 +++--- .../flashy/services/FlashCardServiceImpl.java | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java index 8f8680d..b7dea4d 100644 --- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java +++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java @@ -2,13 +2,12 @@ import com.teamtreehouse.flashy.domain.FlashCard; import com.teamtreehouse.flashy.services.FlashCardService; - +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; -import java.util.List; @Controller public class IndexController { @@ -22,7 +21,8 @@ public void setFlashCardService(FlashCardService flashCardService) { } @RequestMapping("/") - public String index(Model model) { + public + String index(Model model) { StringBuilder ctaBuilder = new StringBuilder(); List cards = flashCardService.getRandomFlashCards(AMOUNT_TO_SHOW); ctaBuilder.append("Refresh your memory about "); diff --git a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java index 5b660e9..1d33202 100644 --- a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java +++ b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java @@ -1,18 +1,16 @@ 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; - import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Random; - -import static java.util.stream.Collectors.toList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; @Service public class FlashCardServiceImpl implements FlashCardService { @@ -62,10 +60,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); }