Skip to content

Commit 5d35124

Browse files
authored
Merge pull request #1 from jscriptor09/bogus-counting
Fixes treehouse-projects#5 by making the cards displayed more standard
2 parents beed2a1 + 1cc5e37 commit 5d35124

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/main/java/com/teamtreehouse/flashy/controllers/IndexController.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@Controller
1414
public class IndexController {
15+
public static final int AMOUNT_TO_SHOW = 3;
1516
private FlashCardService flashCardService;
1617

1718
@Autowired
@@ -22,18 +23,22 @@ public void setFlashCardService(FlashCardService flashCardService) {
2223
@RequestMapping("/")
2324
public String index(Model model) {
2425
StringBuilder ctaBuilder = new StringBuilder();
25-
List<FlashCard> cards = flashCardService.getRandomFlashCards(5);
26+
List<FlashCard> cards = flashCardService.getRandomFlashCards(AMOUNT_TO_SHOW);
2627
ctaBuilder.append("Refresh your memory about ");
2728
for (FlashCard card : cards) {
2829
ctaBuilder.append(card.getTerm());
2930
if (card != cards.get(cards.size() - 1)) {
3031
ctaBuilder.append(", ");
32+
3133
}
3234
}
33-
ctaBuilder.append(" and ");
35+
//
3436
Long totalCount = flashCardService.getCurrentCount();
35-
ctaBuilder.append(totalCount);
36-
ctaBuilder.append(" more");
37+
if(totalCount > AMOUNT_TO_SHOW) {
38+
ctaBuilder.append(" and ");
39+
ctaBuilder.append(totalCount - AMOUNT_TO_SHOW);
40+
ctaBuilder.append(" more");
41+
}
3742
model.addAttribute("cta", ctaBuilder.toString());
3843
model.addAttribute("flashCardCount", totalCount);
3944
return "index";

src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public FlashCard getNextFlashCardBasedOnViews(Map<Long, Long> idToViewCounts) {
6262
continue;
6363
}
6464
Long lowestScore = idToViewCounts.get(leastViewedId);
65-
if (entry.getValue() >= lowestScore) {
66-
break;
65+
if (entry.getValue() < lowestScore) {
66+
leastViewedId = entry.getKey();
67+
//break;
6768
}
68-
leastViewedId = entry.getKey();
6969
}
7070
return flashCardRepository.findOne(leastViewedId);
7171
}

0 commit comments

Comments
 (0)