From ce513c14176092215560f78319227898459ee5b9 Mon Sep 17 00:00:00 2001 From: jihyo Date: Wed, 22 May 2024 14:24:43 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20Music=20=EC=83=9D=EC=84=B1=EC=8B=9C,?= =?UTF-8?q?=20null=EA=B0=92=EC=9D=B4=EB=A9=B4=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=83=9D=EC=84=B1=EC=95=88=EB=90=98=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baebae-BE/.gitignore | 1 + .../answer/repository/AnswerMapper.java | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/baebae-BE/.gitignore b/baebae-BE/.gitignore index a8e346fe..c52d8645 100644 --- a/baebae-BE/.gitignore +++ b/baebae-BE/.gitignore @@ -41,6 +41,7 @@ out/ application.yml application-deploy.yml application-local.yml +application-test.yml ### fcm ### baebae-ff525-firebase-adminsdk-zbc8h-7fd10e518b.json diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java index cd65bd9f..bf4af8c9 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java @@ -11,18 +11,21 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; -import java.util.List; @Component @AllArgsConstructor public class AnswerMapper { public Answer toEntity(AnswerCreateRequest request, Question question, Member member) { - // Music 엔티티 생성 - Music music = Music.builder() - .musicName(request.getMusicName()) - .musicSinger(request.getMusicSinger()) - .musicAudioUrl(request.getMusicAudioUrl()) - .build(); + // 요청에서 music 관련 필드가 있는지 확인 + Music music = null; + if (request.getMusicName() != null || request.getMusicSinger() != null || request.getMusicAudioUrl() != null) { + // Music 엔티티 생성 + music = Music.builder() + .musicName(request.getMusicName()) + .musicSinger(request.getMusicSinger()) + .musicAudioUrl(request.getMusicAudioUrl()) + .build(); + } String senderNickname = question.getNickname(); @@ -35,11 +38,13 @@ public Answer toEntity(AnswerCreateRequest request, Question question, Member me .linkAttachments(request.getLinkAttachments()) .profileOnOff(request.getProfileOnOff()) .createdDate(LocalDateTime.now()) - .music(music) + .music(music) // music이 null이 아닌 경우 설정 .build(); - // Music 엔티티에 Answer 설정 - music.setAnswer(answer); + // Music 엔티티에 Answer 설정 (music이 null이 아닌 경우) + if (music != null) { + music.setAnswer(answer); + } return answer; } @@ -49,7 +54,6 @@ public AnswerDetailResponse toDomain(Answer answer) { Member member = answer.getMember(); Question question = answer.getQuestion(); - return AnswerDetailResponse.of( answer.getId(), question.getId(), @@ -65,7 +69,6 @@ public AnswerDetailResponse toDomain(Answer answer) { music != null ? music.getMusicAudioUrl() : null, answer.getImageFile(), answer.getCreatedDate() - ); }