Skip to content

Commit

Permalink
refactor: addImage 메서드 제거 및 직접적인 이미지 처리 방식으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhacandy committed Sep 16, 2024
1 parent d8345d7 commit ceeaf80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.cotato.csquiz.common.entity.S3Info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.cotato.csquiz.common.error.exception.ImageException;
import org.cotato.csquiz.common.s3.S3Uploader;
import org.cotato.csquiz.domain.generation.entity.ProjectImage;
import org.cotato.csquiz.domain.generation.enums.ProjectImageType;
import org.cotato.csquiz.domain.generation.repository.ProjectImageRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -26,26 +25,28 @@ public class ProjectImageService {
private final ProjectImageRepository projectImageRepository;

@Transactional
public void createProjectImage(Long projectId, MultipartFile logoImage, MultipartFile thumbNailImage, List<MultipartFile> detailImages)
public void createProjectImage(Long projectId, MultipartFile logoImage, MultipartFile thumbNailImage,
List<MultipartFile> detailImages)
throws ImageException {
List<ProjectImage> newImages = new ArrayList<>();

addImage(newImages, logoImage, ProjectImageType.LOGO, projectId, 1);
addImage(newImages, thumbNailImage, ProjectImageType.THUMBNAIL, projectId, 1);
File webpLogoImage = convertToWebp(convert(logoImage));
S3Info logoImageInfo = s3Uploader.uploadFiles(webpLogoImage, PROJECT_IMAGE);
newImages.add(ProjectImage.logoImage(logoImageInfo, projectId));

File webpThumbNailImage = convertToWebp(convert(thumbNailImage));
S3Info thumbNailInfo = s3Uploader.uploadFiles(webpThumbNailImage, PROJECT_IMAGE);
newImages.add(ProjectImage.thumbnailImage(thumbNailInfo, projectId));

if (detailImages != null && !detailImages.isEmpty()) {
for (int orderIndex = 1; orderIndex <= detailImages.size(); orderIndex++) {
MultipartFile detailImage = detailImages.get(orderIndex - 1);
addImage(newImages, detailImage, ProjectImageType.DETAIL, projectId, orderIndex);
File webpDetailImage = convertToWebp(convert(detailImage));
S3Info detailImageInfo = s3Uploader.uploadFiles(webpDetailImage, PROJECT_IMAGE);
newImages.add(ProjectImage.detailImage(detailImageInfo, projectId, orderIndex));
}
}

projectImageRepository.saveAll(newImages);
}

private void addImage( List<ProjectImage> newImages, MultipartFile image, ProjectImageType imageType, Long projectId, int imageOrder) throws ImageException {
File webpImage = convertToWebp(convert(image));
S3Info ImageInfo = s3Uploader.uploadFiles(webpImage, PROJECT_IMAGE);
newImages.add(ProjectImage.createProjectImage(imageType, ImageInfo, projectId, imageOrder));
}
}

0 comments on commit ceeaf80

Please sign in to comment.