Skip to content

Commit

Permalink
이미지 수정 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Johyunik committed Dec 5, 2023
1 parent f710cdb commit f2fdcf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
25 changes: 11 additions & 14 deletions src/main/java/com/weatherfit/board/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,25 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St
throw new RuntimeException(e);
}

for (ImageEntity imageEntity : originalBoard.getImages()) {
imageService.deleteImage(imageEntity);
for (Integer imageId : boardUpdateDTO.getDeletedImages()) {
Optional<ImageEntity> optionalImage = imageRepository.findById(imageId);
ImageEntity imageEntity = optionalImage.orElseThrow(() -> new IllegalArgumentException("해당 이미지가 존재하지 않습니다. id=" + imageId));
imageRepository.delete(imageEntity);
}
originalBoard.getImages().clear();

for (MultipartFile image : images) {
String imageUrl = imageService.saveImage(image);
String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);

if (!imageRepository.existsByImageUrl(imageUrl)) {
ImageEntity imageEntity = ImageEntity.builder()
.fileName(fileName)
.imageUrl(imageUrl)
.boardId(originalBoard)
.build();
imageRepository.save(imageEntity);
ImageEntity imageEntity = ImageEntity.builder()
.fileName(fileName)
.imageUrl(imageUrl)
.boardId(originalBoard)
.build();
imageRepository.save(imageEntity);

originalBoard.getImages().add(imageEntity);

originalBoard.getImages().add(imageEntity);
}
}

BoardEntity boardEntity = BoardEntity.builder()
Expand All @@ -194,8 +193,6 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St
.hashTag(boardUpdateDTO.getHashTag())
.build();

BoardEntity savedBoard = boardRepository.save(boardEntity);

String afterJoiendString = originalBoard.getTemperature() + "/" + String.join("/", originalBoard.getCategory()) + ":" + String.join("/", boardUpdateDTO.getCategory());
String afterJoiendString2 = String.join("/", originalBoard.getHashTag()) + ":" + String.join("/", boardUpdateDTO.getHashTag());

Expand Down
13 changes: 5 additions & 8 deletions src/main/java/com/weatherfit/board/service/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ public String saveImage(MultipartFile file) {
}


public void deleteImage(ImageEntity imageEntity) {
String imageUrl = imageEntity.getImageUrl();
// String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
amazonS3Client.deleteObject(bucketName, imageUrl);
}
// public void deleteImage(ImageEntity imageEntity) {
// String imageUrl = imageEntity.getImageUrl();
//// String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
// amazonS3Client.deleteObject(bucketName, imageUrl);
// }

}



0 comments on commit f2fdcf1

Please sign in to comment.