Skip to content

Commit

Permalink
Add missing table + fix colors if winner is unknown (#45)
Browse files Browse the repository at this point in the history
* poprawki

* Add missing table + fix colors if winner is unknown

---------

Co-authored-by: Krzysztof Lasecki <[email protected]>
  • Loading branch information
congard and KLR2002 authored Jun 11, 2024
1 parent 4efb7c7 commit 47db7cc
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ReportGenerator {
private static final String DEFAULT_FONT_NAME = FontFactory.TIMES;
private static final BaseColor WIN_COLOR = BaseColor.GREEN;
private static final BaseColor LOOSE_COLOR = BaseColor.RED;
private static final BaseColor UNKNOWN_COLOR = BaseColor.LIGHT_GRAY;

private final UserService userService;
private final FightService fightService;
Expand Down Expand Up @@ -100,8 +101,11 @@ private void addFightWeightClassSection(WeightClass weightClass) throws Document
addTableHeader(table, List.of("Fighter 1", "Fighter 2", "Number", "Score"));

fightService.getAllCategoryFights(weightClass).forEach(fight -> {
Function<User, BaseColor> fighterColor = fighter ->
fighter.id() == fight.winnerId() ? WIN_COLOR : LOOSE_COLOR;
Function<User, BaseColor> fighterColor = fighter -> {
if (fight.winnerId() == -1)
return UNKNOWN_COLOR;
return fighter.id() == fight.winnerId() ? WIN_COLOR : LOOSE_COLOR;
};

var f1 = fight.firstUser();
var f2 = fight.secondUser();
Expand All @@ -113,6 +117,8 @@ private void addFightWeightClassSection(WeightClass weightClass) throws Document
text(String.format("%s:%s", fight.score1(), fight.score2()))
));
});

document.add(table);
}

private void addContestantsSection() throws DocumentException {
Expand Down

0 comments on commit 47db7cc

Please sign in to comment.