Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<FlashCard> cards = flashCardService.getRandomFlashCards(AMOUNT_TO_SHOW);
ctaBuilder.append("Refresh your memory about ");
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -62,10 +60,10 @@ public FlashCard getNextFlashCardBasedOnViews(Map<Long, Long> 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);
}
Expand Down