Switched to dict for database access, Made progress on jwt revoking
This commit is contained in:
1 parent
b4ecbeaa37
commit
39d69ee0ca
33 files changed
+28
-30
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,30 +8,30 @@ class ProductService:
|
||||
def get_name(product_id: int):
|
||||
cursor.execute(f"select name from product where product.product_id = {product_id}")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
return result['name']
|
||||
|
||||
@staticmethod
|
||||
def get_manufacturer(product_id: int):
|
||||
cursor.execute(f"select manufacturer from product where product.product_id = {product_id}")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
return result['manufacturer']
|
||||
|
||||
@staticmethod
|
||||
def get_price(product_id: int):
|
||||
cursor.execute(f"select price_pc from product where product.product_id = {product_id}")
|
||||
result = cursor.fetchone()
|
||||
result = cursor['price_pc']
|
||||
return result[0]
|
||||
|
||||
@staticmethod
|
||||
def get_image(product_id: int):
|
||||
cursor.execute(f"select image from product where product.product_id = {product_id}")
|
||||
result = cursor.fetchone()
|
||||
result = cursor['image']
|
||||
return base64.b64encode(result[0]).decode('utf-8')
|
||||
|
||||
@staticmethod
|
||||
def get_image_name(product_id: int):
|
||||
cursor.execute(f"select image_name from product where product.product_id = {product_id}")
|
||||
result = cursor.fetchone()
|
||||
result = cursor['image_name']
|
||||
return result[0]
|
||||
|
||||
@staticmethod
|
||||
@@ -40,13 +40,9 @@ class ProductService:
|
||||
result = cursor.fetchone()
|
||||
|
||||
return {
|
||||
"name": result[0],
|
||||
"manufacturer": result[1],
|
||||
"price": result[2],
|
||||
"image_name": result[3],
|
||||
"image": base64.b64encode(result[4]).decode('utf-8')
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def create_user(username: str, email: str, password: str):
|
||||
print("asd")
|
||||
"name": result['name'],
|
||||
"manufacturer": result['manufacturer'],
|
||||
"price": result['price_pc'],
|
||||
"image_name": result['image_name'],
|
||||
"image": base64.b64encode(result['image']).decode('utf-8')
|
||||
}
|
||||
@@ -31,11 +31,11 @@ class UserService:
|
||||
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
|
||||
|
||||
try:
|
||||
db_cursor.execute("select max(user_id) from user")
|
||||
last_id = db_cursor.fetchone()[0]
|
||||
db_cursor.execute("select max(user_id) as max_id from user")
|
||||
last_id = db_cursor.fetchone()['max_id']
|
||||
|
||||
if last_id < 23000:
|
||||
return {"Failed": "Error occured when fetching last user id"}
|
||||
return {"Failed": "Error occurred when fetching last user id"}
|
||||
|
||||
new_id = last_id + 1
|
||||
|
||||
@@ -53,9 +53,9 @@ class UserService:
|
||||
db_cursor.execute("select user_id, password, last_change from user where username = %s", (username,))
|
||||
result = db_cursor.fetchone()
|
||||
|
||||
user_id = result[0]
|
||||
password_hash = result[1]
|
||||
last_change = result[2]
|
||||
user_id = result['user_id']
|
||||
password_hash = result['password']
|
||||
last_change = result['last_change']
|
||||
|
||||
if user_id is None:
|
||||
return {"Failed": "Username not found"}, 400
|
||||
@@ -73,7 +73,7 @@ class UserService:
|
||||
def update_email(user_id: str, new_email: str) -> Tuple[Union[dict, str], int]:
|
||||
|
||||
if not UserService.__verify_email(new_email):
|
||||
return {"Failed": "Failed to verify email. Try another email"}, 400
|
||||
return {"Failed": "Failed to verify email. Try another email"}, 400
|
||||
|
||||
try:
|
||||
db_cursor.execute("update user set email = %s where user_id = %s", (new_email, user_id))
|
||||
|
||||
Reference in new issue
Block a user