def post(self): token = request.headers.get('Authorization') if not token: abort(403, error="Unauthorized Access (no token)") privilege_handler = PrivilegeHandler(token) if not privilege_handler.schedule_privileges(): abort(403, error="Unauthorized Access (invalid permissions)") parser = reqparse.RequestParser() parser.add_argument('leagueID', type=int, required=True) parser.add_argument('homeTeamID', type=int, required=True) parser.add_argument('awayTeamID', type=int, required=True) parser.add_argument('refereeID', type=int) parser.add_argument('gameTime', type=str) parser.add_argument('fieldName', type=str) parser.add_argument('status', type=str) args = parser.parse_args() league_id = args['leagueID'] home_team_id = args['homeTeamID'] away_team_id = args['awayTeamID'] referee_id = args['refereeID'] game_time = args['gameTime'] field_name = args['fieldName'] status = args['status'] db = DatabaseConnector() db.cursor.callproc('create_game', [ league_id, home_team_id, away_team_id, referee_id, game_time, field_name, status ]) db.conn.commit() db.cursor.close() game_data = { 'leagueName': league_id, 'homeTeamID': home_team_id, 'awayTeamID': away_team_id, 'refereeID': referee_id, 'gameTime': game_time, 'fieldName': field_name, 'status': status, } return {'game': game_data}, 201
def delete(self): token = request.headers.get('Authorization') if not token: abort(403, error="Unauthorized Access (no token)") privilege_handler = PrivilegeHandler(token) if not privilege_handler.schedule_privileges(): abort(403, error="Unauthorized Access (invalid permissions)") parser = reqparse.RequestParser() parser.add_argument('leagueID', type=int, required=True) args = parser.parse_args() query = "SELECT gameID from gameMembers WHERE gameID in (SELECT gameID from games where leagueID = %s)" % args[ 'leagueID'] db = DatabaseConnector() db.cursor.execute(query) res = db.cursor.fetchall() if res: return 400, "Cannot delete schedule were games have been recorded" else: query = "DELETE FROM games WHERE leagueID = %s" % args['leagueID'] db.cursor.execute(query) db.conn.commit() return 200