diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/RootController.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/RootController.java index b1cf2823ef..24f022de6d 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/RootController.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/RootController.java @@ -54,7 +54,7 @@ public ResponseEntity deleteS3( ) { // fileName = "users/" + userId.toString() + "/" + fileName; fileName = "users/" + userId.toString(); - s3Service.deleteFile(fileName); + s3Service.deleteFile(fileName, userId.toString()); return ResponseEntity.ok("delete-s3 called"); } } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java index fc3c7c3631..2a2fb71eb0 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java @@ -151,8 +151,9 @@ public void updateRecord(Long cardViewId, CardViewRequestDTO.UpdateRecord update public void deleteRecord(Long cardViewId) { CardView cardView = cardViewRepository.findById(cardViewId).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 카드뷰입니다.")); // cardView에 엮인 사진들 먼저 삭제 - imageFileService.deleteAll(cardView); - s3Service.deleteFile(cardView.getRecordFileName()); + String userId = cardView.getTripFile().getUser().getId().toString(); + imageFileService.deleteAll(cardView, userId); + s3Service.deleteFile(cardView.getRecordFileName(), userId); boolean isAnalyzed = cardView.getRecordFileStatus().equals("WAIT"); // 만약 tripfile의 Trip이 untitled일 경우 // 만약 tripfile의 크기가 1이라면 tripFile과 cardView 전부 삭제, untitledTrip의 analyzingCount 감소 diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java index a270bb51b2..ed2b2bba06 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java @@ -26,10 +26,10 @@ public class ImageFileService { private final UserService userService; @Transactional - public void deleteAll(CardView cardView) { + public void deleteAll(CardView cardView, String userId) { List imageFiles = imageFileRepository.findAllByCardView(cardView); for (ImageFile imageFile : imageFiles) { - s3Service.deleteFile(imageFile.getFileName()); + s3Service.deleteFile(imageFile.getFileName(), userId); } imageFiles.forEach(imageFileRepository::delete); } @@ -56,7 +56,7 @@ public void deleteImages(List images, Long userId) { for (Long imageId : images) { ImageFile image = imageFileRepository.findById(imageId).orElseThrow(() -> new IllegalArgumentException("해당 이미지가 없습니다.")); userService.validateUserWithCardView(userId, image.getCardView().getId()); - s3Service.deleteFile(image.getFileName()); + s3Service.deleteFile(image.getFileName(), userId.toString()); imageFileRepository.delete(image); } } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/S3Service.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/S3Service.java index 5810f6e840..c81afba1d3 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/S3Service.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/S3Service.java @@ -87,8 +87,9 @@ public ResponseEntity downloadImage(String originalFilename) { } - public void deleteFile(String originalFilename) { - amazonS3.deleteObject(bucket, s3folderPath + originalFilename); + public void deleteFile(String originalFilename, String userId) { + log.info("deleteFile : " + s3folderPath + userId + "/" + originalFilename); + amazonS3.deleteObject(bucket, s3folderPath + userId + "/" + originalFilename); } public void createFolder(String folderName) {