Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 피드 이미지 수정 오류 해결 #92

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading