Сделал фронтенд динамическим и исправил создание услуг (ошибка 405)
This commit is contained in:
@@ -1311,6 +1311,72 @@ def admin_logout():
|
||||
return redirect(f"{base}/application/o/ikp-admin/end-session/")
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
|
||||
@app.route('/admin/services/add', methods=['POST'])
|
||||
def admin_add_service():
|
||||
if not session.get('logged_in'):
|
||||
return jsonify({"status": "error", "message": "Не авторизован"}), 403
|
||||
|
||||
try:
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"status": "error", "message": "Отсутствуют данные запроса"}), 400
|
||||
|
||||
service_id = data.get("id", "").strip()
|
||||
name = data.get("name", "").strip()
|
||||
price = data.get("price", "").strip()
|
||||
price_numeric = data.get("price_numeric")
|
||||
description = data.get("description", "").strip()
|
||||
|
||||
if not service_id or not name or not price:
|
||||
return jsonify({"status": "error", "message": "ID, название и цена обязательны для заполнения"}), 400
|
||||
|
||||
try:
|
||||
price_numeric = float(price_numeric)
|
||||
except (ValueError, TypeError):
|
||||
price_numeric = 0.0
|
||||
|
||||
success = db.add_service(service_id, name, price, price_numeric, description)
|
||||
if success:
|
||||
return jsonify({"status": "success", "message": "Услуга добавлена"})
|
||||
else:
|
||||
return jsonify({"status": "error", "message": f"Услуга с ID '{service_id}' уже существует"}), 400
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "message": str(e)}), 500
|
||||
|
||||
@app.route('/admin/services/edit/<service_id>', methods=['POST'])
|
||||
def admin_edit_service(service_id):
|
||||
if not session.get('logged_in'):
|
||||
return jsonify({"status": "error", "message": "Не авторизован"}), 403
|
||||
|
||||
try:
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"status": "error", "message": "Отсутствуют данные запроса"}), 400
|
||||
|
||||
name = data.get("name", "").strip()
|
||||
price = data.get("price", "").strip()
|
||||
price_numeric = data.get("price_numeric")
|
||||
description = data.get("description", "").strip()
|
||||
is_active = int(data.get("is_active", 1))
|
||||
|
||||
if not name or not price:
|
||||
return jsonify({"status": "error", "message": "Название и цена обязательны для заполнения"}), 400
|
||||
|
||||
try:
|
||||
price_numeric = float(price_numeric)
|
||||
except (ValueError, TypeError):
|
||||
price_numeric = 0.0
|
||||
|
||||
success = db.update_service(service_id, name, price, price_numeric, description, is_active)
|
||||
if success:
|
||||
return jsonify({"status": "success", "message": "Услуга обновлена"})
|
||||
else:
|
||||
return jsonify({"status": "error", "message": "Не удалось обновить услугу (возможно, ID не найден)"}), 404
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "message": str(e)}), 500
|
||||
|
||||
@app.route('/admin/check-payment/<reg_id>', methods=['POST'])
|
||||
def admin_check_payment(reg_id):
|
||||
if not session.get('logged_in'):
|
||||
|
||||
Reference in New Issue
Block a user