@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; }
@RequestMapping(method = RequestMethod.GET, value = "/member/") public List<UserGroupDTO> loadUserGroupsWhereUserIsMember( @PathVariable("userId") final int userId, final Principal principal) { return dtoService.transformUserGroups( userGroupService.loadUserGroupsWhereUserIsMember(userService.load(userId)), getUser(principal)); }
@RequestMapping(method = RequestMethod.GET, value = "/") public List<UserGroupEditDTO> userGroupList(final @PathVariable("userId") int userId) { final List<UserGroup> userGroups = userGroupService.loadUserGroupsWhereUserIsOwner(userService.load(userId)); final Function<UserGroup, UserGroupEditDTO> mapper = userGroup -> { final UserGroupEditDTO dto = new UserGroupEditDTO(); dto.setUserGroupId(userGroup.getId()); dto.setUserGroupName(userGroup.getGroupName()); dto.setCupIds( userGroupService .loadCups(userGroup) .stream() .map(AbstractEntity::getId) .collect(Collectors.toList())); return dto; }; return userGroups.stream().map(mapper).collect(Collectors.toList()); }
@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); }
private User getUser(final Principal principal) { return userService.findByLogin(principal.getName()); }
private UserGroup save(final int userId, final UserGroupEditDTO dto, final UserGroup userGroup) { final User groupOwner = userService.load(userId); userGroup.setOwner(groupOwner); userGroup.setGroupName(dto.getUserGroupName()); return userGroupService.save(userGroup, dto.getCupIds()); }