Product creation
This commit is contained in:
1 parent
f3f1652890
commit
105bbd3e96
2 files changed
+36
-5
No files matched your search
@@ -3,6 +3,8 @@ import base64
|
||||
from flask import abort
|
||||
from mysql.connector import Error
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from app.extensions import db_connection
|
||||
|
||||
class ProductService:
|
||||
@@ -76,11 +78,23 @@ class ProductService:
|
||||
return {"Failed": f"Failed to fetch product info. Error: {e}"}, 500
|
||||
|
||||
@staticmethod
|
||||
def create_listing(name: str, seller_id: str, price: float, image_name: str, image):
|
||||
def create_listing(seller_id: str, name: str, price: float):
|
||||
try:
|
||||
db_cursor.execute("insert into product(seller_id, name, price_pc, image, image_name) values (%s, %s, %s, %s, %s)", (seller_id, name, price, image, image_name))
|
||||
db_connection.commit()
|
||||
with db_connection.cursor() as cursor:
|
||||
rounded_price = round(price, 2)
|
||||
|
||||
cursor.execute("insert into product(seller_id, name, price_pc) values (%s, %s, %s)", (seller_id, name, Decimal(str(rounded_price))))
|
||||
db_connection.commit()
|
||||
except Error as e:
|
||||
return {"Failed": f"Failed to create product. {e}"}, 400
|
||||
|
||||
return {"Success", "Successfully created new product listing"}, 200
|
||||
return {"Success": "Successfully created new product listing"}, 200
|
||||
|
||||
@staticmethod
|
||||
def __is_base64_jpg(decoded_string):
|
||||
try:
|
||||
# Checking if the decoded data represents a valid JPEG image
|
||||
image_type = imghdr.what(None, decoded_data)
|
||||
return image_type == 'jpeg'
|
||||
except Exception:
|
||||
return False
|
||||
Reference in new issue
Block a user