From c56cbcf8f8fde9c4938e34ae5b1939db73c86016 Mon Sep 17 00:00:00 2001 From: Ahn Su-gyeong Date: Mon, 27 May 2024 03:29:17 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20BugFix:=20diary=5Femotion=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=99=B8=EB=9E=98=20=ED=82=A4=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0=20(#74)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../implement/DiaryCommandServiceImpl.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/moodoodle-api/src/main/java/zzangdol/diary/implement/DiaryCommandServiceImpl.java b/moodoodle-api/src/main/java/zzangdol/diary/implement/DiaryCommandServiceImpl.java index b3e2077..1921198 100644 --- a/moodoodle-api/src/main/java/zzangdol/diary/implement/DiaryCommandServiceImpl.java +++ b/moodoodle-api/src/main/java/zzangdol/diary/implement/DiaryCommandServiceImpl.java @@ -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); } @@ -49,23 +51,24 @@ private void checkDiaryDuplication(User user, LocalDate date) { } } - private Diary buildDiary(User user, DiaryCreateRequest request, List 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 emotions) { + emotions.forEach(emotion -> { + DiaryEmotion diaryEmotion = DiaryEmotion.builder() + .diary(diary) + .emotion(emotion) + .build(); + diaryEmotion.addDiaryEmotion(diary); + }); } private Painting buildPainting(DiaryCreateRequest request, String color) {