Skip to content

Commit

Permalink
chore: Music 생성시, null값이면 데이터 생성안되게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jihyo-j committed May 22, 2024
1 parent bd4ab1a commit ce513c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions baebae-BE/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ out/
application.yml
application-deploy.yml
application-local.yml
application-test.yml

### fcm ###
baebae-ff525-firebase-adminsdk-zbc8h-7fd10e518b.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand All @@ -49,7 +54,6 @@ public AnswerDetailResponse toDomain(Answer answer) {
Member member = answer.getMember();
Question question = answer.getQuestion();


return AnswerDetailResponse.of(
answer.getId(),
question.getId(),
Expand All @@ -65,7 +69,6 @@ public AnswerDetailResponse toDomain(Answer answer) {
music != null ? music.getMusicAudioUrl() : null,
answer.getImageFile(),
answer.getCreatedDate()

);
}

Expand Down

0 comments on commit ce513c1

Please sign in to comment.