def post_product(self, product_info, product_thumbnail_images, product_options, connection): """ [어드민] 셀러 상품 등록 Author: Mark Hasung Kim Args: product_info (dict): 등록할 상품에대한 정보 product_thumbnail_images (list) product_options (dict): 등록할 상품의 옵션 정보 (product_colors, product_sizes, product_stock) connection: 커넥션 Returns: data (새로 등록한 product id를 dict형식으로 반환해준다) """ try: seller_dao = SellerDao() product_id = seller_dao.create_product(product_info, connection) product_info['product_id'] = product_id seller_dao.create_product_log(product_info, connection) for product_option in product_options: product_info['product_color_id'] = product_option['colorId'] product_info['product_size_id'] = product_option['sizeId'] product_info['stock'] = product_option['stock'] product_option_id = seller_dao.create_product_option(product_info, connection) product_info['product_option_id'] = product_option_id seller_dao.create_product_option_log(product_info, connection) for product_thumbnail_image in product_thumbnail_images: product_info['image_url'] = product_thumbnail_image product_thumbnail_id = seller_dao.create_new_product_thumbnail(product_info, connection) product_info['product_thumbnail_id'] = product_thumbnail_id seller_dao.create_product_thumbnail_log(product_info, connection) data = {'product_id': product_id} return data except ApiException as e: raise e
def edit_product( self, product_info, product_options, delete_product_options, product_thumbnail_images, delete_product_thumbnails, connection ): """ [어드민] 셀러 상품 수정 Author: Mark Hasung Kim Args: product_info (dict): 수정할 상품에대한 정보 product_options (dict): 수정할 상품의 옵션 정보 (product_colors, product_sizes, product_stock) delete_product_options (list) product_thumbnail_images (list) delete_product_thumbnails (list) connection: 커넥션 Returns: True (상품이 정상적으로 수정 되었으면 True를 반환해준다) """ try: seller_dao = SellerDao() seller_dao.update_product(product_info, connection) seller_dao.create_product_log(product_info, connection) #상품 삭제 요청이 들어올때: if product_info.get('is_delete'): seller_dao.soft_delete_product(product_info, connection) seller_dao.create_product_log(product_info, connection) #상품 옵션 추가 요청이 들어올때: if product_options: for product_option in product_options: product_info['product_color_id'] = product_option['colorId'] product_info['product_size_id'] = product_option['sizeId'] product_info['stock'] = product_option['stock'] product_option_id = seller_dao.create_product_option(product_info, connection) product_info['product_option_id'] = product_option_id seller_dao.create_product_option_log(product_info, connection) #상품 옵션 삭제 요청이 들어올떄: if delete_product_options: for delete_product_option in delete_product_options: product_info['product_option_id'] = delete_product_option check_product_option = seller_dao.check_product_option(product_info, connection) if check_product_option: seller_dao.soft_delete_product_option(product_info, connection) seller_dao.create_product_option_log(product_info, connection) else: raise ApiException(400, PRODUCT_OPTION_DOES_NOT_EXIST) #상품 thumbnail이미지 추가 요청이 들어올때: if product_thumbnail_images: for product_thumbnail_image in product_thumbnail_images: product_info['image_url'] = product_thumbnail_image product_thumbnail_id = seller_dao.create_new_product_thumbnail(product_info, connection) product_info['product_thumbnail_id'] = product_thumbnail_id seller_dao.create_product_thumbnail_log(product_info, connection) #상품 thumbnail이미지 삭제 요청이 들어올때: if delete_product_thumbnails: for delete_product_thumbnail in delete_product_thumbnails: product_info['product_thumbnail_id'] = delete_product_thumbnail check_product_thumbnail = seller_dao.check_product_thumbnail(product_info, connection) if check_product_thumbnail: seller_dao.soft_delete_product_thumbnail(product_info, connection) seller_dao.create_product_thumbnail_log(product_info, connection) else: raise ApiException(400, PRODUCT_THUMBNAIL_DOES_NOT_EXIST) return True except ApiException as e: raise e