52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import base64
 | |
| 
 | |
| from ..extensions import db_cursor as cursor
 | |
| 
 | |
| class ProductService:
 | |
| 
 | |
| 	@staticmethod
 | |
| 	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]
 | |
| 
 | |
| 	@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]
 | |
| 
 | |
| 	@staticmethod
 | |
| 	def get_price(product_id: int):
 | |
| 		cursor.execute(f"select price_pc from product where product.product_id = {product_id}")
 | |
| 		result = cursor.fetchone()
 | |
| 		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()
 | |
| 		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()
 | |
| 		return result[0]
 | |
| 
 | |
| 	@staticmethod
 | |
| 	def get_all_info(product_id: int):
 | |
| 		cursor.execute(f"select name,manufacturer,price_pc,image_name,image from product where product.product_id = {product_id}")
 | |
| 		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") |