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
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 f127754..b7dea4d 100644
--- a/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java
+++ b/src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java
@@ -2,16 +2,17 @@
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 {
+
+ public static final int AMOUNT_TO_SHOW = 3;
private FlashCardService flashCardService;
@Autowired
@@ -20,9 +21,10 @@ public void setFlashCardService(FlashCardService flashCardService) {
}
@RequestMapping("/")
- public String index(Model model) {
+ 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());
@@ -30,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";
}
-
}
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);
}