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); }