File tree 1 file changed +8
-4
lines changed
src/main/java/com/teamtreehouse/flashy/controllers
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 12
12
13
13
@ Controller
14
14
public class IndexController {
15
+ public static final int MAX_ITEMS_TO_SHOW = 3 ;
15
16
private FlashCardService flashCardService ;
16
17
17
18
@ Autowired
@@ -22,18 +23,21 @@ public void setFlashCardService(FlashCardService flashCardService) {
22
23
@ RequestMapping ("/" )
23
24
public String index (Model model ) {
24
25
StringBuilder ctaBuilder = new StringBuilder ();
25
- List <FlashCard > cards = flashCardService .getRandomFlashCards (5 );
26
+ List <FlashCard > cards = flashCardService .getRandomFlashCards (MAX_ITEMS_TO_SHOW );
26
27
ctaBuilder .append ("Refresh your memory about " );
27
28
for (FlashCard card : cards ) {
28
29
ctaBuilder .append (card .getTerm ());
29
30
if (card != cards .get (cards .size () - 1 )) {
30
31
ctaBuilder .append (", " );
31
32
}
32
33
}
33
- ctaBuilder .append (" and " );
34
34
Long totalCount = flashCardService .getCurrentCount ();
35
- ctaBuilder .append (totalCount );
36
- ctaBuilder .append (" more" );
35
+ if (totalCount > MAX_ITEMS_TO_SHOW ) {
36
+ ctaBuilder .append (" and " );
37
+ ctaBuilder .append (totalCount );
38
+ ctaBuilder .append (" more" );
39
+ }
40
+
37
41
model .addAttribute ("cta" , ctaBuilder .toString ());
38
42
model .addAttribute ("flashCardCount" , totalCount );
39
43
return "index" ;
You can’t perform that action at this time.
0 commit comments