Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(#216) : 일기 이미지 하루 지나면 삭제되는 문제 #224

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading