File tree Expand file tree Collapse file tree
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 AMOUNT_TO_SHOW = 3 ;
1516 private FlashCardService flashCardService ;
1617
1718 @ Autowired
@@ -22,18 +23,20 @@ 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 (", " );
3132 }
3233 }
33- ctaBuilder .append (" and " );
3434 Long totalCount = flashCardService .getCurrentCount ();
35- ctaBuilder .append (totalCount );
36- ctaBuilder .append (" more" );
35+ if (totalCount > AMOUNT_TO_SHOW ) {
36+ ctaBuilder .append (" and " );
37+ ctaBuilder .append (totalCount - AMOUNT_TO_SHOW );
38+ ctaBuilder .append (" more" );
39+ }
3740 model .addAttribute ("cta" , ctaBuilder .toString ());
3841 model .addAttribute ("flashCardCount" , totalCount );
3942 return "index" ;
Original file line number Diff line number Diff line change 1- <!DOCTYPE html>
1+ <!DOCTYPE html>
22< html lang ="en " xmlns:th ="http://www.thymeleaf.org ">
33< head >
44 < meta charset ="utf-8 " />
You can’t perform that action at this time.
0 commit comments