Skip to content

Commit

Permalink
๐Ÿž BugFix: diary_emotion ํ…Œ์ด๋ธ” ์™ธ๋ž˜ ํ‚ค ์˜ค๋ฅ˜ ํ•ด๊ฒฐ (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnsugyeong authored May 26, 2024
1 parent e058f36 commit c56cbcf
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public Diary createDiary(User user, DiaryCreateRequest request, String color,
validateDiaryDate(request.getDate());
checkDiaryDuplication(user, request.getDate());
Painting painting = buildPainting(request, color);
Diary diary = buildDiary(user, request, emotions, painting);
Diary diary = buildDiary(user, request, painting);
diary = diaryRepository.save(diary);
addEmotionsToDiary(diary, emotions);
return diaryRepository.save(diary);
}

Expand All @@ -49,23 +51,24 @@ private void checkDiaryDuplication(User user, LocalDate date) {
}
}

private Diary buildDiary(User user, DiaryCreateRequest request, List<Emotion> emotions, Painting painting) {
private Diary buildDiary(User user, DiaryCreateRequest request, Painting painting) {
Diary diary = Diary.builder()
.date(request.getDate())
.content(request.getContent())
.user(user)
.painting(painting)
.build();
emotions.forEach(emotion -> addEmotionToDiary(diary, emotion));
return diary;
}

private void addEmotionToDiary(Diary diary, Emotion emotion) {
DiaryEmotion diaryEmotion = DiaryEmotion.builder()
.diary(diary)
.emotion(emotion)
.build();
diaryEmotion.addDiaryEmotion(diary);
private void addEmotionsToDiary(Diary diary, List<Emotion> emotions) {
emotions.forEach(emotion -> {
DiaryEmotion diaryEmotion = DiaryEmotion.builder()
.diary(diary)
.emotion(emotion)
.build();
diaryEmotion.addDiaryEmotion(diary);
});
}

private Painting buildPainting(DiaryCreateRequest request, String color) {
Expand Down

0 comments on commit c56cbcf

Please sign in to comment.