API_GET_DONE
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 13s
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 13s
This commit is contained in:
@@ -48,7 +48,7 @@ def make_insert_request():
|
||||
if crud.exists_phone(phone_number, user_id):
|
||||
return jsonify({"error": "Phone is exists"}), 404
|
||||
|
||||
response, status = crud.create_phone(user_id, data)
|
||||
response, status, headers = crud.create_phone(user_id, data)
|
||||
|
||||
return jsonify(response)
|
||||
except Exception as e:
|
||||
@@ -67,6 +67,17 @@ def make_get_request():
|
||||
print(paging)
|
||||
|
||||
response = crud.filter_phone(user_id, paging)
|
||||
|
||||
# Kiểm tra xem response có dữ liệu hay không
|
||||
if not response[0]: # Nếu không có dữ liệu
|
||||
return jsonify({"message": "No phone numbers found"}), 404, CORS_HEADERS
|
||||
|
||||
return jsonify({
|
||||
"data": response[0], # Dữ liệu (danh sách các số điện thoại)
|
||||
"status": response[1], # Mã trạng thái HTTP (200)
|
||||
"headers": response[2] # Headers CORS
|
||||
}), response[1], response[2]
|
||||
|
||||
return jsonify(response), 200, CORS_HEADERS
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
10
apps/crud.py
10
apps/crud.py
@@ -103,6 +103,7 @@ def filter_phone(user_id: str, paging):
|
||||
cursor.execute(sql, values) # Thuc Thi Cau Truy Van
|
||||
phones = cursor.fetchall()
|
||||
|
||||
print("Fetched phones: ", phones) # In ra để kiểm tra
|
||||
# Chuyển kết quả thành danh sách các đối tượng với tên trường rõ ràng
|
||||
phone_list = []
|
||||
for phone in phones:
|
||||
@@ -138,6 +139,11 @@ def delete_phone(phone_id: str, user_id: str) -> dict:
|
||||
|
||||
except Exception as e:
|
||||
return {"error": str(e)}, 500
|
||||
finally:
|
||||
if cursor:
|
||||
cursor.close()
|
||||
if conn:
|
||||
conn.close() # Đảm bảo đóng kết nối sau khi xong
|
||||
|
||||
|
||||
def exists_phone(user_id: str, phone_number: str = None, phone_id: str = None):
|
||||
@@ -145,14 +151,14 @@ def exists_phone(user_id: str, phone_number: str = None, phone_id: str = None):
|
||||
conn = init_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
if phone_number: # Nếu là `POST`, kiểm tra sự tồn tại của phone_number
|
||||
if phone_number: # Nếu là `POST`, kiểm tra sự tồn tại của phone_number => Nghia la kiem tra so
|
||||
cursor.execute("""
|
||||
SELECT 1
|
||||
FROM ailbl_user_phone
|
||||
WHERE user_id = %s AND phone_number = %s
|
||||
""", (user_id, phone_number))
|
||||
|
||||
elif phone_id: # Nếu là `DELETE`, kiểm tra sự tồn tại của phone_id
|
||||
elif phone_id: # Nếu là `DELETE`, kiểm tra sự tồn tại của phone_id => Nghia la kiem tra id cua so phone do
|
||||
cursor.execute("""
|
||||
SELECT 1
|
||||
FROM ailbl_user_phone
|
||||
|
||||
Reference in New Issue
Block a user