ProfileDone
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 21s
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 21s
This commit is contained in:
45
apps/crud.py
45
apps/crud.py
@@ -1,30 +1,27 @@
|
||||
import io
|
||||
from flask import Response
|
||||
from helpers import init_db_connection, CORS_HEADERS
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def get_profile(user_id):
|
||||
def get_profile(id):
|
||||
try:
|
||||
conn = init_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Truy van thong tin nguoi dung tu bang ailbl_user_profiles
|
||||
query = "SELECT * FROM ailbl_user_profiles WHERE user_id = %s"
|
||||
cursor.execute(query, (user_id,))
|
||||
query = "SELECT * FROM ailbl_user_profile WHERE id = %s"
|
||||
cursor.execute(query, (id,))
|
||||
profile = cursor.fetchone() # fetchone la gi ?
|
||||
|
||||
if profile:
|
||||
return {
|
||||
"user_id": profile[0],
|
||||
"id": profile[0],
|
||||
"first_name": profile[1],
|
||||
"last_name": profile[2],
|
||||
"dob": profile[3],
|
||||
"gender": profile[4],
|
||||
"address": profile[5],
|
||||
"phone": profile[6],
|
||||
"created": profile[7],
|
||||
"modified": profile[8]
|
||||
"created": profile[5],
|
||||
"modified": profile[6]
|
||||
}, 200, CORS_HEADERS
|
||||
else:
|
||||
return {"error": "Profile not found"}, 404, CORS_HEADERS
|
||||
@@ -35,24 +32,22 @@ def get_profile(user_id):
|
||||
conn.close()
|
||||
|
||||
|
||||
def update_profile(user_id, data):
|
||||
def update_profile(id, data):
|
||||
try:
|
||||
conn = init_db_connection()
|
||||
cursor = conn.cursor()
|
||||
# Cap nhat thong tin nguoi dung trong bang ailbl_user_profiles
|
||||
query = """
|
||||
UPDATE ailbl_user_profiles
|
||||
SET first_name = %s, last_name = %s, dob = %s, gender = %s, address = %s, phone = %s, modified = NOW()
|
||||
WHERE user_id = %s
|
||||
UPDATE ailbl_user_profile
|
||||
SET first_name = %s, last_name = %s, dob = %s, gender = %s, modified = NOW()
|
||||
WHERE id = %s
|
||||
"""
|
||||
cursor.execute(query, (
|
||||
data.get("first_name"),
|
||||
data.get("last_name"),
|
||||
data.get("dob"),
|
||||
data.get("gender"),
|
||||
data.get("address"),
|
||||
data.get("phone"),
|
||||
user_id
|
||||
id
|
||||
))
|
||||
conn.commit()
|
||||
return {"message": "Profile updated successfully"}, 200, CORS_HEADERS
|
||||
@@ -64,23 +59,21 @@ def update_profile(user_id, data):
|
||||
conn.close()
|
||||
|
||||
|
||||
def insert_profile(user_id, data):
|
||||
def insert_profile(id, data):
|
||||
try:
|
||||
conn = init_db_connection()
|
||||
cursor = conn.cursor()
|
||||
# Tao moi thong tin nguoi dung trong bang ailbl_user_profiles
|
||||
# Tao moi thong tin nguoi dung trong bang ailbl_user_profile
|
||||
query = """
|
||||
INSERT INTO ailbl_user_profiles (user_id, first_name, last_name, dob, gender, address, phone, created, modified)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
|
||||
INSERT INTO ailbl_user_profile (id, first_name, last_name, dob, gender, created, modified)
|
||||
VALUES (%s, %s, %s, %s, %s, NOW(), NOW())
|
||||
"""
|
||||
cursor.execute(query, (
|
||||
user_id,
|
||||
id,
|
||||
data.get("first_name"),
|
||||
data.get("last_name"),
|
||||
data.get("dob"),
|
||||
data.get("gender"),
|
||||
data.get("address"),
|
||||
data.get("phone")
|
||||
))
|
||||
conn.commit()
|
||||
return {"message": "Profile created successfully"}, 201, CORS_HEADERS
|
||||
@@ -91,14 +84,14 @@ def insert_profile(user_id, data):
|
||||
conn.close()
|
||||
|
||||
|
||||
def delete_profile(user_id):
|
||||
def delete_profile(id):
|
||||
try:
|
||||
conn = init_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Xoa thong tin nguoi dung trong bang ailbl_user_profiles
|
||||
query = "DELETE FROM ailbl_user_profiles WHERE user_id = %s"
|
||||
cursor.execute(query, (user_id,))
|
||||
query = "DELETE FROM ailbl_user_profile WHERE id = %s"
|
||||
cursor.execute(query, (id,))
|
||||
|
||||
conn.commit()
|
||||
return {"message": "Profile deleted successfully"}, 200, CORS_HEADERS
|
||||
|
||||
Reference in New Issue
Block a user