Skip to content

Commit

Permalink
Merge pull request #92 from Team-baebae/feature/question/#34
Browse files Browse the repository at this point in the history
fix: 피드 이미지 수정 오류 해결
  • Loading branch information
jihyo-j authored May 19, 2024
2 parents fa46295 + f01f9c8 commit 4702acd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> imageFiles; // 이미지 파일 경로를 저장하는 리스트
private String imageFile; // 이미지 파일 경로를 저장하는 리스트

@Column(name = "content", columnDefinition = "TEXT", nullable = false)
private String content;
Expand All @@ -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<String> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public AnswerDetailResponse toDomain(Answer answer) {
Music music = answer.getMusic();
Member member = answer.getMember();
Question question = answer.getQuestion();
List<String> imageFiles = answer.getImageFiles();
String imageUrl = (imageFiles != null && !imageFiles.isEmpty()) ? imageFiles.get(0) : null;

return AnswerDetailResponse.of(
answer.getId(),
Expand All @@ -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()

);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@RequiredArgsConstructor
@Service
public class AnswerService {


private final AnswerRepository answerRepository;
private final MemberRepository memberRepository;
private final QuestionRepository questionRepository;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -155,7 +157,6 @@ public void deleteAnswer(Long answerId) {
answerRepository.delete(answer);
}


@Transactional
public Map<ReactionValue, Boolean> hasReacted(Long answerId, Long memberId) {
Member member = memberRepository.findById(memberId)
Expand Down

0 comments on commit 4702acd

Please sign in to comment.