Updated claude big changes
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import logging
|
||||
from flask import request, jsonify
|
||||
from flask import request
|
||||
from flask_login import login_required
|
||||
from geopy.geocoders import Nominatim
|
||||
from app.customer import customer
|
||||
from app import db
|
||||
from app.common.decorators import login_required as common_login_required
|
||||
from app.common.responses import error_response, success_response
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from datetime import datetime
|
||||
@@ -21,18 +22,19 @@ from app.classes.admin import Admin_Company
|
||||
from app.classes.auto import Auto_Delivery,Auto_Delivery_schema
|
||||
from app.classes.stats_customer import Stats_Customer
|
||||
from app.schemas import CreateCustomerSchema, UpdateCustomerSchema, validate_request
|
||||
from app.constants import DEFAULT_TANK_SIZE_GALLONS, DEFAULT_PAGE_SIZE
|
||||
import string
|
||||
import random
|
||||
import secrets
|
||||
|
||||
|
||||
def generate_random_number_string(length):
|
||||
# Ensure the length is at least 1
|
||||
if length < 1:
|
||||
raise ValueError("Length must be at least 1")
|
||||
|
||||
# Generate a random number with the specified length
|
||||
random_number = ''.join(random.choices(string.digits, k=length))
|
||||
|
||||
|
||||
# Generate a cryptographically secure random number string
|
||||
random_number = ''.join(secrets.choice(string.digits) for _ in range(length))
|
||||
|
||||
return random_number
|
||||
|
||||
|
||||
@@ -45,7 +47,7 @@ def all_customers_around():
|
||||
.query(Customer_Customer) \
|
||||
.all()
|
||||
customer_schema = Customer_Customer_schema(many=True)
|
||||
return jsonify(customer_schema.dump(customer_list))
|
||||
return success_response({"customers": customer_schema.dump(customer_list)})
|
||||
|
||||
|
||||
@customer.route("/all/<int:page>", methods=["GET"])
|
||||
@@ -55,7 +57,7 @@ def all_customers(page):
|
||||
pagination all customers
|
||||
"""
|
||||
logger.info(f"GET /customer/all/{page} - Fetching customers page {page}")
|
||||
per_page_amount = 100
|
||||
per_page_amount = DEFAULT_PAGE_SIZE
|
||||
if page is None:
|
||||
offset_limit = 0
|
||||
elif page == 1:
|
||||
@@ -69,7 +71,7 @@ def all_customers(page):
|
||||
.limit(per_page_amount).offset(offset_limit)
|
||||
|
||||
customer_schema = Customer_Customer_schema(many=True)
|
||||
return jsonify(customer_schema.dump(customer_list))
|
||||
return success_response({"customers": customer_schema.dump(customer_list)})
|
||||
|
||||
|
||||
@customer.route("/<int:customer_id>", methods=["GET"])
|
||||
@@ -83,7 +85,7 @@ def get_a_customer(customer_id):
|
||||
.filter(Customer_Customer.id == customer_id)
|
||||
.first())
|
||||
customer_schema = Customer_Customer_schema(many=False)
|
||||
return jsonify(customer_schema.dump(get_customer))
|
||||
return success_response({"customer": customer_schema.dump(get_customer)})
|
||||
|
||||
|
||||
@customer.route("/description/<int:customer_id>", methods=["GET"])
|
||||
@@ -117,8 +119,7 @@ def get_a_customer_description(customer_id):
|
||||
.filter(Customer_Description.customer_id == customer_id)
|
||||
.first())
|
||||
customer_schema = Customer_Description_schema(many=False)
|
||||
return jsonify(customer_schema.dump(get_customer_description))
|
||||
|
||||
return success_response({"description": customer_schema.dump(get_customer_description)})
|
||||
|
||||
|
||||
@customer.route("/tank/<int:customer_id>", methods=["GET"])
|
||||
@@ -139,7 +140,7 @@ def get_a_customer_tank(customer_id):
|
||||
last_tank_inspection = None,
|
||||
tank_status = False,
|
||||
outside_or_inside = True,
|
||||
tank_size = 275,
|
||||
tank_size = DEFAULT_TANK_SIZE_GALLONS,
|
||||
)
|
||||
db.session.add(new_tank)
|
||||
db.session.commit()
|
||||
@@ -148,9 +149,7 @@ def get_a_customer_tank(customer_id):
|
||||
.filter(Customer_Tank_Inspection.customer_id == customer_id)
|
||||
.first())
|
||||
customer_schema = Customer_Tank_Inspection_schema(many=False)
|
||||
return jsonify(customer_schema.dump(get_customer_tank))
|
||||
|
||||
|
||||
return success_response({"tank": customer_schema.dump(get_customer_tank)})
|
||||
|
||||
|
||||
@customer.route("/create", methods=["POST"])
|
||||
@@ -276,22 +275,20 @@ def create_customer():
|
||||
last_tank_inspection=None,
|
||||
tank_status = False,
|
||||
outside_or_inside = True,
|
||||
tank_size=275,
|
||||
tank_size=DEFAULT_TANK_SIZE_GALLONS,
|
||||
)
|
||||
db.session.add(new_tank)
|
||||
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
return success_response({
|
||||
'user': {
|
||||
'user_id': new_customer.id,
|
||||
'user_name': new_customer.customer_last_name,
|
||||
'user_email': new_customer.customer_email,
|
||||
},
|
||||
}), 200
|
||||
|
||||
})
|
||||
|
||||
|
||||
@customer.route("/edit/<int:customer_id>", methods=["PUT"])
|
||||
@@ -307,7 +304,7 @@ def edit_customer(customer_id):
|
||||
.first())
|
||||
|
||||
if not get_customer:
|
||||
return jsonify({"error": "Customer not found"}), 404
|
||||
return error_response("Customer not found", 404)
|
||||
|
||||
get_customer_description = (db.session
|
||||
.query(Customer_Description)
|
||||
@@ -390,14 +387,12 @@ def edit_customer(customer_id):
|
||||
db.session.add(get_customer)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
return success_response({
|
||||
'user': {
|
||||
'user_name': get_customer.customer_last_name,
|
||||
|
||||
'user_email': get_customer.customer_email,
|
||||
},
|
||||
}), 200
|
||||
})
|
||||
|
||||
|
||||
@customer.route("/delete/<int:customer_id>", methods=["DELETE"])
|
||||
@@ -421,13 +416,12 @@ def delete_customer(customer_id):
|
||||
|
||||
db.session.delete(get_customer)
|
||||
db.session.commit()
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
return success_response({
|
||||
'user': {
|
||||
'user_name': get_customer.customer_last_name,
|
||||
'user_email': get_customer.customer_email,
|
||||
},
|
||||
}), 200
|
||||
})
|
||||
|
||||
|
||||
@customer.route("/count", methods=["GET"])
|
||||
@@ -440,10 +434,7 @@ def customer_count():
|
||||
.query(Customer_Customer)
|
||||
.count())
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'count': get_customer
|
||||
}), 200
|
||||
return success_response({'count': get_customer})
|
||||
|
||||
|
||||
@customer.route("/automatic/status/<int:customer_id>", methods=["GET"])
|
||||
@@ -464,10 +455,7 @@ def customer_automatic_status(customer_id):
|
||||
status = 0
|
||||
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'status': status
|
||||
}), 200
|
||||
return success_response({'status': status})
|
||||
|
||||
|
||||
@customer.route("/automatic/deliveries", methods=["GET"])
|
||||
@@ -480,9 +468,9 @@ def get_all_automatic_deliveries():
|
||||
try:
|
||||
deliveries = Auto_Delivery.query.all()
|
||||
schema = Auto_Delivery_schema(many=True)
|
||||
return jsonify(schema.dump(deliveries)), 200
|
||||
return success_response({"deliveries": schema.dump(deliveries)})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
return error_response(str(e), 500)
|
||||
|
||||
|
||||
|
||||
@@ -531,10 +519,7 @@ def customer_automatic_assignment(customer_id):
|
||||
|
||||
if get_main_credit_card is None:
|
||||
status = 2
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'status': status
|
||||
}), 200
|
||||
return success_response({'status': status})
|
||||
|
||||
# customer becomes an automatic
|
||||
if get_auto is None:
|
||||
@@ -567,11 +552,8 @@ def customer_automatic_assignment(customer_id):
|
||||
status = 1
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'status': status
|
||||
}), 200
|
||||
|
||||
return success_response({'status': status})
|
||||
|
||||
|
||||
@customer.route("/edit/tank/<int:customer_id>", methods=["PUT"])
|
||||
@@ -583,7 +565,7 @@ def edit_customer_tank(customer_id):
|
||||
logger.info(f"PUT /customer/edit/tank/{customer_id} - Editing customer tank info")
|
||||
get_customer = db.session.query(Customer_Customer).filter(Customer_Customer.id == customer_id).one_or_none()
|
||||
if not get_customer:
|
||||
return jsonify({"ok": False, "error": "Customer not found"}), 404
|
||||
return error_response("Customer not found", 404)
|
||||
|
||||
get_customer_description = db.session.query(Customer_Description).filter(Customer_Description.customer_id == customer_id).first()
|
||||
if not get_customer_description:
|
||||
@@ -626,4 +608,4 @@ def edit_customer_tank(customer_id):
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({"ok": True}), 200
|
||||
return success_response()
|
||||
|
||||
Reference in New Issue
Block a user