File tree Expand file tree Collapse file tree
src/main/java/com/teamtreehouse/flashy/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212
1313@ Controller
1414public class IndexController {
15+ public static final int MAX_ITEMS_TO_SHOW = 3 ;
1516 private FlashCardService flashCardService ;
1617
1718 @ Autowired
@@ -22,18 +23,21 @@ 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 (MAX_ITEMS_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 (", " );
3132 }
3233 }
33- ctaBuilder .append (" and " );
3434 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+
3741 model .addAttribute ("cta" , ctaBuilder .toString ());
3842 model .addAttribute ("flashCardCount" , totalCount );
3943 return "index" ;
You can’t perform that action at this time.
0 commit comments