diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/entity/Answer.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/entity/Answer.java index 798b408b..370e141d 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/entity/Answer.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/entity/Answer.java @@ -40,10 +40,8 @@ public class Answer { @Column(name = "nickname") private String nickname; - @ElementCollection - @CollectionTable(name = "answer_image_files", joinColumns = @JoinColumn(name = "answer_id")) @Column(name = "image_file") - private List imageFiles; // 이미지 파일 경로를 저장하는 리스트 + private String imageFile; // 이미지 파일 경로를 저장하는 리스트 @Column(name = "content", columnDefinition = "TEXT", nullable = false) private String content; @@ -70,9 +68,9 @@ public class Answer { private boolean profileOnOff; public static Answer of(Long id, Question question, Member member, String nickname, String content, - List imageFiles, Music music, String linkAttachments, String imageUrl, LocalDateTime createdDate, + String imageFile, Music music, String linkAttachments, String imageUrl, LocalDateTime createdDate, ReactionCount reactionCount, boolean profileOnOff) { - return new Answer(id, question, member, nickname, imageFiles, content, music, linkAttachments, imageUrl, createdDate, null, reactionCount, profileOnOff); + return new Answer(id, question, member, nickname, imageFile, content, music, linkAttachments, imageUrl, createdDate, null, reactionCount, profileOnOff); } } 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 b4267ba4..12cdea30 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 @@ -46,8 +46,6 @@ public AnswerDetailResponse toDomain(Answer answer) { Music music = answer.getMusic(); Member member = answer.getMember(); Question question = answer.getQuestion(); - List imageFiles = answer.getImageFiles(); - String imageUrl = (imageFiles != null && !imageFiles.isEmpty()) ? imageFiles.get(0) : null; return AnswerDetailResponse.of( answer.getId(), @@ -62,7 +60,7 @@ public AnswerDetailResponse toDomain(Answer answer) { music != null ? music.getMusicName() : null, music != null ? music.getMusicSinger() : null, music != null ? music.getMusicAudioUrl() : null, - imageUrl, + answer.getImageFile(), answer.getCreatedDate() ); diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java index e276cd85..945bb92f 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java @@ -40,6 +40,8 @@ @RequiredArgsConstructor @Service public class AnswerService { + + private final AnswerRepository answerRepository; private final MemberRepository memberRepository; private final QuestionRepository questionRepository; @@ -64,7 +66,7 @@ public AnswerDetailResponse createAnswer(AnswerCreateRequest request, Long membe if (!imageFile.isEmpty()) { try (InputStream inputStream = imageFile.getInputStream()) { String imageUrl = s3ImageStorageService.uploadFile(member.getId().toString(), answer.getId().toString(), "image", 0, inputStream, imageFile.getSize(), imageFile.getContentType()); - answer.setImageFiles(List.of(imageUrl)); + answer.setImageFile(imageUrl); } catch (IOException e) { throw new BusinessException(AnswerError.IMAGE_PROCESSING_ERROR); } @@ -133,7 +135,7 @@ public AnswerDetailResponse updateAnswer(Long answerId, AnswerCreateRequest requ if (request.isUpdateImage() && imageFile != null && !imageFile.isEmpty()) { try (InputStream inputStream = imageFile.getInputStream()) { String imageUrl = s3ImageStorageService.uploadFile(answer.getMember().getId().toString(), answerId.toString(), "image", 0, inputStream, imageFile.getSize(), imageFile.getContentType()); - answer.setImageFiles(List.of(imageUrl)); + answer.setImageFile(imageUrl); } catch (IOException e) { throw new BusinessException(AnswerError.IMAGE_PROCESSING_ERROR); } @@ -155,7 +157,6 @@ public void deleteAnswer(Long answerId) { answerRepository.delete(answer); } - @Transactional public Map hasReacted(Long answerId, Long memberId) { Member member = memberRepository.findById(memberId)