diff --git a/config.py b/config.py index 9dfe8d4..bd5e212 100644 --- a/config.py +++ b/config.py @@ -18,4 +18,3 @@ class Config: # Admin ADMIN_KEY = os.getenv('ADMIN_KEY') - COLLECT_COOLDOWN = os.getenv('COLLECT_COOLDOWN') diff --git a/interbend/routes/admin_routes.py b/interbend/routes/admin_routes.py index b772692..0af3b69 100644 --- a/interbend/routes/admin_routes.py +++ b/interbend/routes/admin_routes.py @@ -1,9 +1,7 @@ -import mysql.connector from flask import Blueprint from interbend.db import db, get_user from interbend.auth import * import hmac -import decimal from werkzeug.security import generate_password_hash admin_bp = Blueprint('admin_bp', __name__) @@ -15,13 +13,13 @@ def _keychecker(key): return True -@admin_bp.route('/set-job', methods=['POST']) -def set_job(): +@admin_bp.route('/salary', methods=['POST']) +def set_salary(): data = request.get_json() bid = data.get('bid') - job_id = data.get('job') + salary_class = data.get('class') key = data.get('key') - if not bid or not job_id or not key: + if not bid or not salary_class or not key: return jsonify({"error": "BID, salary class, and key are required"}), 400 if not _keychecker(key): return jsonify({"error":"Admin Key required"}), 403 @@ -29,41 +27,10 @@ def set_job(): if not user: return jsonify({"error": "User not found"}), 404 with db.cursor(dictionary=True) as cur: - cur.execute("UPDATE user_jobs SET job_id = %s WHERE bid = %s", (job_id, bid)) + cur.execute("UPDATE users SET salary_class = %s WHERE bid = %s", (salary_class, bid)) db.commit() return jsonify({"message": "Salary class updated successfully"}), 200 -@admin_bp.route('/add-money', methods=['POST', 'PATCH']) -def add_money(): - data = request.get_json() - if not data: - return jsonify({"error": "No data provided"}), 400 - bid = data.get('bid') - amount = data.get('amount') - key = data.get('key') - if not bid or not money or not key: - return jsonify({"error": "BID, Amount and AdminKey are required"}), 400 - if not _keychecker(key): - return jsonify({"error":"Admin Key required"}), 403 - try: - amount_dec = decimal.Decimal(amount) - except (ValueError, decimal.InvalidOperation): - return jsonify({"error": "Invalid amount"}), 400 - user = get_user(bid) - if not user: - return jsonify({"error": "User not found"}), 404 - balance = user["balance"] - new_balance = balance + amount_dec - try: - with db.cursor(dictionary=True) as cur: - cur.execute("UPDATE users SET balance = %s WHERE bid = %s", (new_balance, bid)) - db.commit() - return jsonify({"message": "Money successfully updated!"}), 200 - except mysql.connector.Error as err: - db.rollback() - current_app.logger.error(f"Database error in add_money: {err}") - return jsonify({"error":"A database error occurred, please try again later."}), 500 - @admin_bp.route('/change-password', methods=['POST', 'PATCH']) def change_password(): data = request.get_json() diff --git a/interbend/routes/transaction_routes.py b/interbend/routes/transaction_routes.py index e1fe733..906f8f5 100644 --- a/interbend/routes/transaction_routes.py +++ b/interbend/routes/transaction_routes.py @@ -1,6 +1,4 @@ from flask import Blueprint - -from config import Config from interbend.db import db, get_user from interbend.auth import * import mysql.connector @@ -15,41 +13,10 @@ def get_balance(): return jsonify({"error": "User not found."}), 404 return jsonify({"balance": user["balance"]}) -@transactions_bp.route('/collect', methods=['POST']) -@jwt_required -def collect(): - user_bid = request.bid - data = request.get_json() - cooldown = Config.COLLECT_COOLDOWN - try: - db.start_transaction() - with db.cursor(dictionary=True) as cur: - query = """ - SELECT uj.job_id, \ - uj.collected, \ - j.salary_class, \ - s.money AS salary_amount - FROM user_jobs uj \ - JOIN jobs j ON uj.job_id = j.job_id \ - JOIN salary s ON j.salary_class = s.class - WHERE uj.user_bid = %s \ - """ - cur.execute(query, (user_bid,)) - user_jobs = cur.fetchall() - if not user_jobs: - db.rollback() - return jsonify({"error": "You do not have a job to collect a salary from."}), 400 - total_payout = 0 - jobs_collected_count = 0 - now = datetime.now(timezone.utc) - - - - @transactions_bp.route('/transfer', methods=['POST']) @jwt_required def transfer(): - # Ignore warning because it's dynamically added via jwt required. + # Ignore warning because its dynamically added via jwt required. user_bid = request.bid data = request.get_json() fbid = data.get('from')