@RequestMapping(method = RequestMethod.GET, value = "/winners/bets/") public CupWinnersBetsDTO all( @PathVariable("cupId") final int cupId, final HttpServletRequest request, final Principal principal) { final User currentUser = userService.findByLogin(principal.getName()); final Cup cup = cupService.load(cupId); final Language language = AppContext.read(request.getSession()).getLanguage(); final CupWinnersBetsDTO result = new CupWinnersBetsDTO(); result.setWinnersCount(cup.getWinnersCount()); result.setWinners(dtoService.transformTeams(cup.getCategory(), toTeams(cup), currentUser)); final boolean isCupBetsAreHiddenYet = !cupBetsService.isCupBettingFinished(cup); final List<User> users = getUsers(cup); final List<UserCupBetsDTO> usersCupBets = newArrayList(); for (final User user : users) { final List<CupTeamBet> cupTeamBets = cupBetsService.load(cup, user); final UserCupBetsDTO userCupBetsDTO = new UserCupBetsDTO(); userCupBetsDTO.setUser(dtoService.transformUser(user)); final List<CupTeamBetDTO> userCupBets = dtoService.transformCupTeamBets(cupTeamBets, user); if (isCupBetsAreHiddenYet) { replaceTeamsWithFakeData(cup, userCupBets, language); } userCupBetsDTO.setUserCupBets(userCupBets); usersCupBets.add(userCupBetsDTO); } result.setUsersCupBets(usersCupBets); return result; }
private TestData() { user = new User(); user.setId(1000); user.setUsername("The User"); category = new Category("NBA"); category.setId(1); final PointsCalculationStrategy pointsCalculationStrategy = new PointsCalculationStrategy(); pointsCalculationStrategy.setStrategyName("Abstract strategy"); pointsCalculationStrategy.setPointsForMatchScore(6); pointsCalculationStrategy.setPointsForMatchWinner(1); pointsCalculationStrategy.setPointsDelta(3); pointsCalculationStrategy.setPointsForBetWithinDelta(3); cup = new Cup("The Cup", category); cup.setId(2); cup.setPointsCalculationStrategy(pointsCalculationStrategy); final Team team1 = new Team("Team 1", category); team1.setId(101); final Team team2 = new Team("Team 2", category); team2.setId(102); final Team team3 = new Team("Team 3", category); team2.setId(103); final Team team4 = new Team("Team 4", category); team2.setId(104); final MatchBet matchBet1 = new MatchBet(); matchBet1.setId(10000); matchBet1.setUser(user); matchBet1.setBetScore1(100); matchBet1.setBetScore2(110); matchBet1.setMatch(getMatch(team1, team2, 100, 110)); matchBets.add(matchBet1); final MatchBet matchBet2 = new MatchBet(); matchBet2.setId(10000); matchBet2.setUser(user); matchBet2.setBetScore1(100); matchBet2.setBetScore2(110); matchBet2.setMatch(getMatch(team3, team4, 100, 120)); matchBets.add(matchBet2); }
@RequestMapping("cups/{cupId}/logo/") public void cupLogo(final @PathVariable("cupId") int cupId, final HttpServletResponse response) throws IOException { final Cup cup = cupService.load(cupId); final File cupLogo = logoService.getLogoFile(cup); if (isLogo(cupLogo)) { downloadFile(cupLogo, response); return; } downloadFile(logoService.getLogoFile(cup.getCategory()), response); }
private void replaceTeamsWithFakeData( final Cup cup, final List<CupTeamBetDTO> userCupBets, final Language language) { for (final CupTeamBetDTO userCupBet : userCupBets) { final TeamDTO team = userCupBet.getTeam(); final TeamDTO fakeTeam = new TeamDTO(); fakeTeam.setCategory(team.getCategory()); fakeTeam.setTeamId(0); fakeTeam.setTeamLogo("/resources/img/team-logo-not-found.png"); fakeTeam.setTeamName( translatorService.translate( "Team name is hidden till $1", language, dateTimeService.formatDateTimeUI(cup.getCupStartTime()))); userCupBet.setTeam(fakeTeam); } }
@RequestMapping(method = RequestMethod.GET, value = "/winners/") public List<TeamDTO> winners(@PathVariable("cupId") final int cupId, final Principal principal) { final User currentUser = userService.findByLogin(principal.getName()); final Cup cup = cupService.load(cupId); return dtoService.transformTeams(cup.getCategory(), toTeams(cup), currentUser); }