def on_post(self, req, resp, id): match = m.Match.get(id=id) Privilege.checkOrganizer(req.context['user'], match.tournamentId) data = req.context['data'] assistPlayerId = data.get('assistPlayerId') scorePlayerId = data.get('scorePlayerId') callahan = data.get('callahan', False) homePoint = bool(data['homePoint']) tournament = m.Tournament.get(id=match.tournamentId) if not tournament.ready: raise ValueError("Tournament isn't ready") if not match.active: raise ValueError("Match isn't active") teamId = match.homeTeamId if homePoint else match.awayTeamId self.checkPlayers(match.tournamentId, teamId, assistPlayerId, scorePlayerId, callahan) with m.db.transaction(): if not callahan: if assistPlayerId: self.updatePlayerStatistic(match.tournamentId, assistPlayerId, match.id, 'A') if scorePlayerId: self.updatePlayerStatistic(match.tournamentId, scorePlayerId, match.id, 'S') order, homeScore, awayScore = Queries.getLastPoint(match.id) order += 1 if homePoint: homeScore += 1 else: awayScore += 1 m.Point.insert( homePoint=homePoint, matchId=match.id, order=order, assistPlayerId=assistPlayerId if not callahan else None, scorePlayerId=scorePlayerId if not callahan else None, homeScore=homeScore, awayScore=awayScore, callahan=callahan).execute() self.updateMatchScore(match.id, homePoint) point = Queries.getPoints(matchId=match.id, order=order)[0] req.context['result'] = point resp.status = falcon.HTTP_201
def on_delete(self, req, resp, id): match = m.Match.get(id=id) Privilege.checkOrganizer(req.context['user'], match.tournamentId) # TODO: unite this two queries order, homeScore, awayScore = Queries.getLastPoint(match.id) point = Queries.getPoints(match.id, order)[0] assistPlayerId = point['assistPlayer']['id'] scorePlayerId = point['scorePlayer']['id'] with m.db.transaction(): # delete from match table self.updateMatchScore(match.id, point['homePoint'], (-1)) # delete players statistics if assistPlayerId: self.updatePlayerStatistic(match.tournamentId, assistPlayerId, match.id, 'A', (-1)) if scorePlayerId: self.updatePlayerStatistic(match.tournamentId, scorePlayerId, match.id, 'S', (-1)) # delete point m.Point.delete().where(m.Point.matchId == match.id, m.Point.order == order).execute()
def on_get(self, req, resp, id): match = Queries.getMatches(matchId=id)[0] match['points'] = Queries.getPoints(id) req.context['result'] = match