Skip to content

Commit

Permalink
Merge pull request #131 from kookmin-sw/backend/develop/v3
Browse files Browse the repository at this point in the history
backend/develop/v3
  • Loading branch information
J-Yong99 authored May 3, 2024
2 parents 6d515c3 + 16f4cc3 commit 0d49ff8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ResponseEntity<String> deleteS3(
) {
// fileName = "users/" + userId.toString() + "/" + fileName;
fileName = "users/" + userId.toString();
s3Service.deleteFile(fileName);
s3Service.deleteFile(fileName, userId.toString());
return ResponseEntity.ok("delete-s3 called");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 감소
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageFile> imageFiles = imageFileRepository.findAllByCardView(cardView);
for (ImageFile imageFile : imageFiles) {
s3Service.deleteFile(imageFile.getFileName());
s3Service.deleteFile(imageFile.getFileName(), userId);
}
imageFiles.forEach(imageFileRepository::delete);
}
Expand All @@ -56,7 +56,7 @@ public void deleteImages(List<Long> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ public ResponseEntity<UrlResource> 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) {
Expand Down

0 comments on commit 0d49ff8

Please sign in to comment.