Skip to content

Commit

Permalink
수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Johyunik committed Dec 2, 2023
1 parent 3a21eb7 commit f3f0f6b
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 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,8 +165,6 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St
throw new RuntimeException(e);
}

List<ImageEntity> newImages = new ArrayList<>();

for (MultipartFile image : images) {
String imageUrl = imageService.saveImage(image);

Expand All @@ -176,17 +174,8 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St
.build();
imageRepository.save(imageEntity);

newImages.add(imageEntity);
}

// 새로운 이미지 URL과 기존의 이미지 URL을 비교하여 이미지가 수정되었는지 판단합니다.
for (ImageEntity originalImage : originalBoard.getImages()) {
boolean isModified = newImages.stream().noneMatch(newImage -> newImage.getImageUrl().equals(originalImage.getImageUrl()));
if (isModified) {
// 이미지가 수정되었을 경우, 기존의 이미지를 삭제합니다.
imageService.deleteImage(originalImage.getImageUrl());
imageRepository.delete(originalImage);
}
// 기존 게시글의 이미지 목록에 새로운 이미지를 추가합니다.
originalBoard.getImages().add(imageEntity);
}

// 삭제된 이미지 처리
Expand Down Expand Up @@ -218,7 +207,6 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St
originalBoard.setContent(boardUpdateDTO.getContent());
originalBoard.setCategory(boardUpdateDTO.getCategory());
originalBoard.setHashTag(boardUpdateDTO.getHashTag());
originalBoard.setImages(newImages);
boardRepository.save(originalBoard);

// 카프카 전송
Expand Down

0 comments on commit f3f0f6b

Please sign in to comment.