diff --git a/Backend/main.py b/Backend/main.py index 29014f4573b8b631d4c4d206ac5ccb146bfffacb..b43a2c615a8714b305f7e8e522725ce69d9632fe 100644 --- a/Backend/main.py +++ b/Backend/main.py @@ -1,7 +1,7 @@ from utils.application import app from routes.category import get_category from routes.home import get_home -from routes.order import post_pay_products +#from routes.order import post_pay_products #from routes.cart import get_cart from routes.login import post_login, post_logout, post_register from routes.product import get_product_by_id, get_product_all, get_products_by_search diff --git a/Backend/routes/product.py b/Backend/routes/product.py index 392c554df1b138a80e8d7e4a3734350d94a83356..db2ee10cacb5c72409fd70bdfd9118833ecaa803 100644 --- a/Backend/routes/product.py +++ b/Backend/routes/product.py @@ -22,8 +22,10 @@ def get_product_by_id(product_id): if len(products) > 1: return jsonify({"message": "Database error"}), 500 + print(products) + # Use function to turn it into a json style object - jsonProduct = sql_product_to_json(products)[0] + jsonProduct = sql_product_to_json(products) return jsonify(jsonProduct) @@ -31,7 +33,8 @@ def get_product_all(): # Get all the products cur = mysql.connection.cursor() cur.execute(''' - SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity FROM product + SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity, brand.name, brand.description + FROM product INNER JOIN brand ON product.brand_id = brand.brand_id ''') products = cur.fetchall() @@ -46,7 +49,8 @@ def get_products_by_search(search): cur = mysql.connection.cursor() # Search in product name and description cur.execute(''' - SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity FROM product + SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity, brand.name, brand.description + FROM product INNER JOIN brand ON product.brand_id = brand.brand_id WHERE product.name LIKE %s OR product.description LIKE %s ''', ('%' + search + '%', '%' + search + '%')) diff --git a/Backend/utils/helpers.py b/Backend/utils/helpers.py index d999bf83f42861b0a0a7617e4216daeefb0cea2e..15b4c2eef8203187d7c374a00d836f04530a8881 100644 --- a/Backend/utils/helpers.py +++ b/Backend/utils/helpers.py @@ -1,13 +1,15 @@ def sql_product_to_json(products): jsonProducts = [] for product in products: - product_id, name, description, price, stock_quantity = product + product_id, name, description, price, stock_quantity, brand_name, brand_desc = product jsonProducts.append({ "product_id": product_id, "name": name, "description": description, "price": price, - "stock_quantity": stock_quantity + "stock_quantity": stock_quantity, + "brand_name": brand_name, + "brand_description": brand_desc }) return jsonProducts \ No newline at end of file