예제 #1
0
	def get(self, user_id):
		args = tournamentParser.parse_args()
		tournamentID = args['tournamentID']

		tournament  = Tournament.objects(id=tournamentID).first()
		if tournament is None:
			raise InvalidUsage('Tournament Not Found',404)

		return tournament_serialize(tournament)
예제 #2
0
	def get(self, user_id):
		args = tournamentParser.parse_args()
		page = args['page']
		if page is None:
			page = 0

		profile = Profile.objects(user=user_id).first()
		tournaments = Tournament.objects(creator=profile).only('id','creator','isEnded','createTime','rounds','isFull')

		return tournament_search_serialize(tournaments[5*page:5*(page+1)])
예제 #3
0
	def get(self, user_id):
		args = tournamentParser.parse_args()
		tournamentName = args['tournamentName']
		page = args['page']

		if tournamentName is None:
			tournamentName = ''
		if page is None:
			page = 0

		tournaments = Tournament.objects(tournamentName__icontains=tournamentName).only('id','creator','isEnded','createTime','rounds','isFull')

		tournaments = tournaments.filter(isEnded=False).order_by('-createTime')[10*page:10*(page+1)]

		return tournament_search_serialize(tournaments)
예제 #4
0
	def delete(self, user_id):
		args = tournamentParser.parse_args()
		tournamentID = args['tournamentID']
		if tournamentID is None:
			raise InvalidUsage('Provide tournament id please')

		profile = Profile.objects(user=user_id).first()

		tournament = Tournament.objects(id=tournamentID).first()
		if tournament is None:
			raise InvalidUsage('Tournament not found',404)
		if tournament.creator != profile:
			raise InvalidUsage('Unauthorized',401)
		# More deletions need to be added
		rule = Rule.objects(tournament=tournament).first()
		if rule is not None:
			rule.delete()
		for round in tournament.rounds:
			round.delete()

		tournament.delete()
		return {'status':'success'}
예제 #5
0
	def post(self, user_id):
		args = tournamentParser.parse_args()
		tournamentID = args['tournamentID']

		tournament = Tournament.objects(id=tournamentID).first()
		if tournament is None:
			raise InvalidUsage('Tournament not found',404)
		if tournament.isEnded is True or tournament.isFull is True:
			raise InvalidUsage('Tournament full or has ended',403)

		profile = Profile.objects(user=user_id).first()
		team = profile.LOLTeam
		if team is None or team.captain != profile:
			raise InvalidUsage('Only captain can join tournament',401)
		if team.inGame is True:
			raise InvalidUsage('One team can only join one tournament at the same time',403)
		# join the first round
		round = tournament.rounds[0]
		round.checkInNumber += 1
		if round.checkInNumber == tournament.size:
			tournament.isFull = True
		tournament.save()

		if len(round.readyTeam) is 0:
			round.update(add_to_set__readyTeam=team)
		else:
			opponent = round.readyTeam[0]
			round.update(pull__readyTeam=opponent)
			match = MatchHistory(tournament=tournament,tournamentName=tournament.tournamentName,round=round,teams=[opponent,team])
			match.save()
			team.update(add_to_set__matchHistory=match)
			opponent.update(add_to_set__matchHistory=match)
			round.update(add_to_set__matches=match)
		team.inGame = True
		team.save()

		return {'status' : 'success'}