Skip to content
This repository was archived by the owner on May 13, 2019. It is now read-only.

Fewer examples #8

Merged
merged 2 commits into from
Dec 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@Controller
public class IndexController {
public static final int AMOUNT_TO_SHOW = 3;
private FlashCardService flashCardService;

@Autowired
Expand All @@ -22,18 +23,21 @@ public void setFlashCardService(FlashCardService flashCardService) {
@RequestMapping("/")
public String index(Model model) {
StringBuilder ctaBuilder = new StringBuilder();
List<FlashCard> cards = flashCardService.getRandomFlashCards(5);
List<FlashCard> cards = flashCardService.getRandomFlashCards(AMOUNT_TO_SHOW);
ctaBuilder.append("Refresh your memory about ");
for (FlashCard card : cards) {
ctaBuilder.append(card.getTerm());
if (card != cards.get(cards.size() - 1)) {
ctaBuilder.append(", ");
}
}
ctaBuilder.append(" and ");
Long totalCount = flashCardService.getCurrentCount();
ctaBuilder.append(totalCount);
ctaBuilder.append(" more");
if (totalCount > AMOUNT_TO_SHOW){
ctaBuilder.append(" and ");
ctaBuilder.append(totalCount - AMOUNT_TO_SHOW);
ctaBuilder.append(" more");
}

model.addAttribute("cta", ctaBuilder.toString());
model.addAttribute("flashCardCount", totalCount);
return "index";
Expand Down