def join_team(self, hackathon_id, team_name, user): """Join a team will create a record on user_team_rel table which status will be 0. :type hackathon_id: int :param hackathon_id: hackathon id :type team_name: str | unicode :param team_name: team name :type user: User :param user: the user to join a team :rtype: dict :return: if user already joined team or team not exist, return bad request. Else, return a dict of joined details. """ if self.db.find_first_object_by(UserTeamRel, hackathon_id=hackathon_id, user_id=g.user.id): return precondition_failed( "You have joined another team, please quit first.") team = self.__get_team_by_name(hackathon_id, team_name) if team: candidate = UserTeamRel(join_time=self.util.get_now(), update_time=self.util.get_now(), status=TeamMemberStatus.Init, hackathon_id=hackathon_id, user_id=user.id, team_id=team.id) self.db.add_object(candidate) return candidate.dic() else: return not_found("team not found !")
def join_team(self, hackathon_id, team_name, user): """Join a team will create a record on user_team_rel table which status will be 0. :type hackathon_id: int :param hackathon_id: hackathon id :type team_name: str | unicode :param team_name: team name :type user: User :param user: the user to join a team :rtype: dict :return: if user already joined team or team not exist, return bad request. Else, return a dict of joined details. """ if self.db.find_first_object_by(UserTeamRel, hackathon_id=hackathon_id, user_id=g.user.id): return precondition_failed("You have joined another team, please quit first.") team = self.__get_team_by_name(hackathon_id, team_name) if team: candidate = UserTeamRel(join_time=self.util.get_now(), update_time=self.util.get_now(), status=TeamMemberStatus.Init, hackathon_id=hackathon_id, user_id=user.id, team_id=team.id) self.db.add_object(candidate) return candidate.dic() else: return not_found("team not found !")
def join_team(self, user, team_id): """Join a team will create a record on user_team_rel table which status will be 0. :type user: User :param user: the user to join a team :rtype: dict :return: if user already joined team or team not exist, return bad request. Else, return a dict of joined details. """ if self.db.find_first_object_by(UserTeamRel, user_id=user.id, team_id=team_id): return ok("You already joined this team.") team = self.__get_team_by_id(team_id) if not team: return not_found() cur_team = self.__get_valid_team_by_user(user.id, team.hackathon_id) if cur_team and cur_team.team.user_team_rels.count() > 1: return precondition_failed("Team leader cannot join another team for team member count greater than 1") if not self.register_manager.is_user_registered(user.id, team.hackathon): return precondition_failed("user not registerd") candidate = UserTeamRel(join_time=self.util.get_now(), update_time=self.util.get_now(), status=TeamMemberStatus.Init, hackathon_id=team.hackathon.id, user_id=user.id, team_id=team.id) self.db.add_object(candidate) return candidate.dic()
def create_team(self, kwargs): """Create new team by given args. user only allow to join or create 1 team. So if user joined or created team before, will be get failed when creating new team. :type kwargs: dict :param kwargs: a dict of required information to create new team :rtype: dict :return: created team information """ user_team_rel = self.__get_team_by_user(g.user.id, g.hackathon.id) if user_team_rel: self.log.debug( "fail to create team since user is already in some team.") return precondition_failed("you must leave the current team first") if "team_name" not in kwargs: return bad_request("Please provide a team name") # check team name to avoid duplicate name team_name = kwargs["team_name"] if self.__get_team_by_name(g.hackathon.id, team_name): return precondition_failed( "The team name is existed, please provide a new name") team = Team(name=team_name, description=kwargs.get("description"), git_project=kwargs.get("git_project"), logo=kwargs.get("logo"), create_time=self.util.get_now(), update_time=self.util.get_now(), leader_id=g.user.id, hackathon_id=g.hackathon.id) self.db.add_object(team) user_team_rel = UserTeamRel(join_time=self.util.get_now(), update_time=self.util.get_now(), status=TeamMemberStatus.Approved, hackathon_id=g.hackathon.id, user_id=g.user.id, team_id=team.id) self.db.add_object(user_team_rel) return team.dic()