2024-03-05 16:01:26 +01:00
import base64
from . . extensions import db_cursor as cursor
class ProductService :
@staticmethod
def get_name ( product_id : int ) :
2024-03-07 22:37:49 +01:00
cursor . execute ( f " select name from product where product.id = { product_id } " )
2024-03-05 16:01:26 +01:00
result = cursor . fetchone ( )
2024-03-05 21:35:58 +01:00
return result [ ' name ' ]
2024-03-05 16:01:26 +01:00
@staticmethod
def get_manufacturer ( product_id : int ) :
2024-03-07 22:37:49 +01:00
cursor . execute ( f " select user.displayname as seller from product inner join user on product.seller_id = user.id where product.id = { product_id } " )
2024-03-05 16:01:26 +01:00
result = cursor . fetchone ( )
2024-03-07 22:37:49 +01:00
return result [ ' seller ' ]
2024-03-05 16:01:26 +01:00
@staticmethod
def get_price ( product_id : int ) :
2024-03-07 22:37:49 +01:00
cursor . execute ( f " select price_pc from product where product.id = { product_id } " )
2024-03-05 21:35:58 +01:00
result = cursor [ ' price_pc ' ]
2024-03-05 16:01:26 +01:00
return result [ 0 ]
@staticmethod
def get_image ( product_id : int ) :
2024-03-07 22:37:49 +01:00
cursor . execute ( f " select image from product where product.id = { product_id } " )
2024-03-05 21:35:58 +01:00
result = cursor [ ' image ' ]
2024-03-05 16:01:26 +01:00
return base64 . b64encode ( result [ 0 ] ) . decode ( ' utf-8 ' )
@staticmethod
def get_image_name ( product_id : int ) :
2024-03-07 22:37:49 +01:00
cursor . execute ( f " select image_name from product where product.id = { product_id } " )
2024-03-05 21:35:58 +01:00
result = cursor [ ' image_name ' ]
2024-03-05 16:01:26 +01:00
return result [ 0 ]
@staticmethod
def get_all_info ( product_id : int ) :
2024-03-07 22:37:49 +01:00
cursor . execute ( f " select name, user.displayname as seller, price_pc, image_name, image from product inner join user on product.seller_id = user.id where product.id = { product_id } " )
2024-03-05 16:01:26 +01:00
result = cursor . fetchone ( )
return {
2024-03-05 21:35:58 +01:00
" name " : result [ ' name ' ] ,
2024-03-07 22:37:49 +01:00
" seller " : result [ ' seller ' ] ,
2024-03-05 21:35:58 +01:00
" price " : result [ ' price_pc ' ] ,
" image_name " : result [ ' image_name ' ] ,
" image " : base64 . b64encode ( result [ ' image ' ] ) . decode ( ' utf-8 ' )
2024-03-07 22:16:29 +01:00
}
@staticmethod
def create_listing ( ) :
print ( " asd " )