AdminAddressDone
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 19s

This commit is contained in:
QuangMinh_123
2025-12-11 13:47:00 +00:00
parent 5359f80e3c
commit c77d8c0421
3 changed files with 108 additions and 69 deletions

View File

@@ -1,7 +1,7 @@
import crud
import logging
from flask import jsonify, request
ALLOWED_IMAGE_TYPES = {"image/jpeg", "image/png", "image/gif", "image/webp"}
from filters import AddressPage
def main():
@@ -31,26 +31,59 @@ def main():
def make_insert_request():
try:
user_id = request.headers.get("X-User")
file = request.files.get("avatar")
if not user_id or not file:
return jsonify({"error": "user_id or file is required"}), 400
if file.mimetype not in ALLOWED_IMAGE_TYPES:
return jsonify(
{"error": "Invalid file type. Only JPG, PNG, GIF, WEBP are allowed."}
), 400
response, status = crud.update_or_create_avatar(user_id, file)
# Lấy user_id từ header X-User
user_id = request.headers.get("X-Fission-Params-UserId")
if not user_id:
return jsonify({"error": "user_id is required"}), 400
data = request.get_json() # Lấy dữ liệu từ body request
if not data:
return jsonify({"error": "Address data is required"}), 400
address = data.get("address")
if not address:
return jsonify({"error": "Address is required"}), 400
# Kiểm tra nếu địa chỉ đã tồn tại cho người dùng này
if crud.exists_address_for_post(user_id, address):
return jsonify({"error": "Address already exists for this user"}), 409
# Tạo mới địa chỉ người dùng
response, status = crud.create_address(user_id, data)
return jsonify(response), status
except Exception as e:
return jsonify({"error": str(e)}), 500
def make_get_request():
try:
user_id = request.headers.get("X-User")
user_id = request.headers.get("X-Fission-Params-UserId")
if not user_id:
return jsonify({"error": "user_id is required"}), 400
return crud.get_avatar_url(user_id)
# Lấy tham số filter và phân trang từ request
# Sử dụng AddressPage để lấy filter và phân trang
paging = AddressPage.from_request_queries()
print(paging)
# Gọi hàm CRUD để lấy danh sách địa chỉ của user_id với phân trang và lọc
response = crud.filter_address(user_id, paging)
return jsonify(
response,
), 200
# Kiểm tra xem response có dữ liệu không
# if not response[0]: # Nếu không có dữ liệu
# return jsonify({"message": "No addresses found"}), 404
# return jsonify({
# "data": response[0], # Dữ liệu (danh sách các địa chỉ)
# "status": response[1], # Mã trạng thái HTTP (200)
# "headers": response[2] # Headers CORS
# }), response[1], response[2]
except Exception as e:
return jsonify({"error": str(e)}), 500