Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions market/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,30 @@ def upload_service_images(entity: Any, image_file) -> None:
# 엔티티 타입 별 쿼리 생성
if isinstance(entity, Service):
ServiceImage.objects.create(market_service=entity, image=image_file)
elif isinstance(entity, ServiceOption):
ServiceOptionImage.objects.create(
service_option=entity, image=image_file
)

except ValidationError as e:
raise ValidationError(f"Validation Error: {str(e)}")
except Exception as e:
raise e

@staticmethod
@transaction.atomic
def upload_service_option_images(entity: Any, image_files) -> None:
"""
서비스 소개 이미지를 S3에 업로드 및 데이터베이스에 저장하는 함수
"""
try:
# 파일 유효성 검증
validate_image_files(image_files)

# 엔티티 타입 별 쿼리 생성
if isinstance(entity, ServiceOption):
bulk_images: List[ServiceOptionImage] = []
for image_file in image_files:
bulk_images.append(
ServiceOptionImage(service_option=entity, image=image_file)
)
ServiceOptionImage.objects.bulk_create(bulk_images)

except ValidationError as e:
raise ValidationError(f"Validation Error: {str(e)}")
Expand Down
4 changes: 2 additions & 2 deletions market/views/image_upload_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def post(self, request, **kwargs):
if not image_files:
raise ValidationError("There are no image files to upload")

self.service.upload_service_images(
entity=market_service_option, image_file=image_files
self.service.upload_service_option_images(
entity=market_service_option, image_files=image_files
)

return Response(
Expand Down
Loading