Skip to content

Commit 25ea700

Browse files
authored
Merge pull request #11 from IverBand/bogus-counting
Addresses issue #8 by fixing the bogus counting of card views
2 parents eabbb7e + d25a111 commit 25ea700

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import com.teamtreehouse.flashy.domain.FlashCard;
44
import com.teamtreehouse.flashy.services.FlashCardService;
5-
5+
import java.util.List;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.stereotype.Controller;
88
import org.springframework.ui.Model;
99
import org.springframework.web.bind.annotation.RequestMapping;
1010

11-
import java.util.List;
1211

1312
@Controller
1413
public class IndexController {
@@ -22,7 +21,8 @@ public void setFlashCardService(FlashCardService flashCardService) {
2221
}
2322

2423
@RequestMapping("/")
25-
public String index(Model model) {
24+
public
25+
String index(Model model) {
2626
StringBuilder ctaBuilder = new StringBuilder();
2727
List<FlashCard> cards = flashCardService.getRandomFlashCards(AMOUNT_TO_SHOW);
2828
ctaBuilder.append("Refresh your memory about ");

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package com.teamtreehouse.flashy.services;
22

3+
import static java.util.stream.Collectors.toList;
4+
35
import com.teamtreehouse.flashy.domain.FlashCard;
46
import com.teamtreehouse.flashy.repositories.FlashCardRepository;
5-
6-
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.stereotype.Service;
8-
97
import java.util.Collection;
108
import java.util.Collections;
119
import java.util.List;
1210
import java.util.Map;
1311
import java.util.Random;
14-
15-
import static java.util.stream.Collectors.toList;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.stereotype.Service;
1614

1715
@Service
1816
public class FlashCardServiceImpl implements FlashCardService {
@@ -62,10 +60,10 @@ public FlashCard getNextFlashCardBasedOnViews(Map<Long, Long> idToViewCounts) {
6260
continue;
6361
}
6462
Long lowestScore = idToViewCounts.get(leastViewedId);
65-
if (entry.getValue() >= lowestScore) {
66-
break;
63+
if (entry.getValue() < lowestScore) {
64+
leastViewedId = entry.getKey();
6765
}
68-
leastViewedId = entry.getKey();
66+
6967
}
7068
return flashCardRepository.findOne(leastViewedId);
7169
}

0 commit comments

Comments
 (0)