feat: image upload on product
This commit is contained in:
@@ -67,6 +67,8 @@ class ProductService(BaseService):
|
||||
del product_dict['id']
|
||||
del product_dict['barcodes']
|
||||
del product_dict['barcode_template']
|
||||
del product_dict['image_url']
|
||||
del product_dict['images']
|
||||
if request.product.barcode_template:
|
||||
product_dict['barcode_template_id'] = request.product.barcode_template.id
|
||||
|
||||
@@ -150,9 +152,12 @@ class ProductService(BaseService):
|
||||
|
||||
async def upload_image(self, product_id: int, file_bytes: bytes) -> ProductUploadImageResponse:
|
||||
try:
|
||||
product = await self.get_by_id(product_id)
|
||||
product: Product = await self.session.get(Product, product_id)
|
||||
if not product:
|
||||
raise Exception("Неудалось найти товар с указанным ID")
|
||||
# removing previous images
|
||||
for image in product.images:
|
||||
await self.session.delete(image)
|
||||
s3_uploader = S3Uploader(config.S3_API_KEY)
|
||||
response = await s3_uploader.upload(file_bytes)
|
||||
response_url = response.get('link')
|
||||
|
||||
Reference in New Issue
Block a user