Skip to content

Commit

Permalink
Fix(#216) : 일기 이미지 하루 지나면 삭제되는 문제 (#224)
Browse files Browse the repository at this point in the history
* Fix : 유저, 일기 이미지 자동삭제 되지 않게 수정

* Fix : 일기 내 이미지 url 쉼표로 구분하여 영구화하도록 수정
  • Loading branch information
Astin01 authored Oct 7, 2024
1 parent f95a4bc commit e43d4dc
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void updateDiary(Long userId, Long diaryId, DiaryUpdateRequest request) {
}

private void updateDiary(Long diaryId, DiaryUpdateRequest request) {
Diary diary = diaryRepository.findById(diaryId).orElseThrow(() -> new DiaryNotExistsException("해당 일기가 존재하지 않습니다."));
Diary diary = diaryRepository.findById(diaryId)
.orElseThrow(() -> new DiaryNotExistsException("해당 일기가 존재하지 않습니다."));
deleteDiaryImage(request);
diary.getDiaryDayContent().clear();
diary.updateDiary(request);
Expand All @@ -103,7 +104,7 @@ private void updateDiary(Long diaryId, DiaryUpdateRequest request) {

private void saveDiaryDayContent(Diary savedDiary, DiaryCreateRequest request) {
for (DiaryDayRequest dayRequest : request.getDiaryDayRequests()) {
s3Uploader.markImagePermanent(dayRequest.getDiaryDayContentImages());
makeDiaryImagePermanent(dayRequest.getDiaryDayContentImages());
DiaryDayContent diaryDayContent = DiaryDayContent.builder()
.diary(savedDiary)
.content(dayRequest.getContent())
Expand All @@ -115,6 +116,15 @@ private void saveDiaryDayContent(Diary savedDiary, DiaryCreateRequest request) {
}
}

private void makeDiaryImagePermanent(String diaryDayContentImages) {
if (!diaryDayContentImages.isEmpty()) {
String[] contentImages = diaryDayContentImages.split(",");
for (String contentImage : contentImages) {
s3Uploader.markImagePermanent(contentImage);
}
}
}

private void updateDiaryDayContent(Diary savedDiary, DiaryUpdateRequest request) {
diaryDayContentRepository.deleteById(savedDiary.getId());
for (DiaryUpdateDayRequest dayRequest : request.getDiaryDayRequests()) {
Expand Down

0 comments on commit e43d4dc

Please sign in to comment.