// Sending request------------------------------------------------------------------
  @RequestMapping(value = "/sendRequest", method = RequestMethod.GET)
  public ModelAndView sendRequest(@RequestParam int teamId) {

    ModelAndView result;
    Collection<Team> teams;
    Collection<Team> teamsRequested = new ArrayList<Team>();
    Team team;
    Boolean showSend = true;
    Collection<RequestTeam> requestTeam;
    User principal;

    principal = userService.findByPrincipal();
    team = teamService.findOne(teamId);
    requestTeamService.sendRequest(teamId);
    teams = teamService.findAllOtherUser(principal.getId());
    requestTeam = requestTeamService.findAllRequestSendFromUser(principal.getId());

    for (RequestTeam r : requestTeam) {
      teamsRequested.add(r.getTeam());
    }

    result = new ModelAndView("team/list");

    result.addObject("teams", teams);
    result.addObject("teamsRequested", teamsRequested);
    result.addObject("showSend", showSend);
    result.addObject("requestURI", "team/user/listAllTeams.do");

    return result;
  }
예제 #2
0
  public void joinTeam(Team team, RequestTeam requestTeam) {

    User user;

    user = requestTeam.getUser();

    requestTeam.setRequest(true);
    team.getUsers().add(user);
    user.getTeams().add(team);

    requestTeamService.save(requestTeam);
    save(team);
    userService.save(user);
  }
  // Accepting request------------------------------------------------------------------
  @RequestMapping(value = "/acceptRequest", method = RequestMethod.GET)
  public ModelAndView acceptRequest(@RequestParam int requestTeamId) {

    ModelAndView result;
    RequestTeam requestTeam;

    requestTeam = requestTeamService.findOne(requestTeamId);
    teamService.joinTeam(requestTeam.getTeam(), requestTeam);

    result = new ModelAndView("team/list");

    result.addObject("requestURI", "team/user/list.do");

    return result;
  }