Skip to content
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 @@ -27,7 +27,7 @@ public class Question {
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Column(nullable = false, columnDefinition = "TEXT")
@Column(columnDefinition = "TEXT")
private String content;

@Column(name = "image_url", columnDefinition = "TEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class QuestionComment {
@JoinColumn(name = "parent_comment_id")
private QuestionComment parentComment;

@Column(nullable = false, columnDefinition = "TEXT")
@Column(columnDefinition = "TEXT")
private String content;

@Column(name = "image_url", columnDefinition = "TEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public QuestionResDTO.CommentCreateRes createComment(
// 1. 대댓글 여부 확인: parentCommentId가 있으면 부모 댓글 조회
QuestionComment parentComment = resolveParentComment(request.getParentCommentId(), question);

// builder 전에 검증 추가
validateCommentContent(request.getContent(), request.getImageUrl());

// 2. 댓글 엔티티 생성 및 저장
LocalDateTime now = LocalDateTime.now();
QuestionComment comment = QuestionComment.builder()
Expand Down Expand Up @@ -248,6 +251,9 @@ public QuestionResDTO.CreateRes createQuestion(Long sessionId, QuestionReqDTO.Cr
User loginUser = findLoginUser(userId);
StudySession session = findSession(sessionId);

// builder 전에 검증 추가
validateQuestionContent(request.getContent(), request.getImageUrl());

Question question = Question.builder()
.session(session)
.user(loginUser)
Expand Down Expand Up @@ -793,4 +799,22 @@ private record QuestionSummaryContext(
Set<Long> likedQuestionIds
) {
}

// 질문은 내용 또는 이미지 중 하나는 반드시 있어야 함
private void validateQuestionContent(String content, String imageUrl) {
boolean hasContent = content != null && !content.isBlank();
boolean hasImage = imageUrl != null && !imageUrl.isBlank();
if (!hasContent && !hasImage) {
throw new QuestionException(HttpStatus.BAD_REQUEST, "질문 내용 또는 이미지 중 하나는 필수입니다.");
}
}

// 댓글은 내용 또는 이미지 중 하나는 반드시 있어야 함
private void validateCommentContent(String content, String imageUrl) {
boolean hasContent = content != null && !content.isBlank();
boolean hasImage = imageUrl != null && !imageUrl.isBlank();
if (!hasContent && !hasImage) {
throw new QuestionException(HttpStatus.BAD_REQUEST, "댓글 내용 또는 이미지 중 하나는 필수입니다.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- 이미지만 단독 업로드가 가능하도록 content NOT NULL 제약 해제
ALTER TABLE question ALTER COLUMN content DROP NOT NULL;
ALTER TABLE question_comment ALTER COLUMN content DROP NOT NULL;
Loading