def post_league(): body = request.get_json() start_date = datetime.strptime(body['start'], DATE_FORMAT) end_date = datetime.strptime(body['end'], DATE_FORMAT) if start_date > end_date: return make_response(jsonify(EndBeforeStart=errors['endBeforeStart']), 400) league_duration = (end_date - start_date).days if league_duration > DAYS_IN_YEAR: return make_response( jsonify(LeagueDurationTooLong=errors['leagueDurationTooLong']), 400) start_pos = body.get('startPos') or DEFAULT_START_POS invite_code = Utility.getInviteCode() g.cursor.execute( "Insert INTO League(name, start, end, startPos, inviteCode, ownerId) " + "VALUES (%s, %s, %s, %s, %s, %s)", [ body['name'], start_date, end_date, start_pos, invite_code, g.user['id'] ]) return jsonify(inviteCode=invite_code, id=g.cursor.lastrowid, startPos=start_pos)
def post_league(): body = request.get_json() inviteCode = Utility.getInviteCode() try: start = time.strptime(body['start'], DATE_FORMAT) end = time.strptime(body['end'], DATE_FORMAT) except: return make_response(jsonify(error=errors['invalidDate']), 400) g.cursor.execute( "INSERT INTO League(name, start, end, startPos, inviteCode, ownerId) " + "VALUES (%s, %s, %s, %s, %s, %s)", [ body['name'], start, end, body['startPos'], inviteCode, body['ownerId'] ]) return jsonify(inviteCode=inviteCode, id=g.cursor.lastrowid)