diff --git a/src/main/java/econo/buddybridge/comment/exception/CommentErrorCode.java b/src/main/java/econo/buddybridge/comment/exception/CommentErrorCode.java index 55f803b..c93a184 100644 --- a/src/main/java/econo/buddybridge/comment/exception/CommentErrorCode.java +++ b/src/main/java/econo/buddybridge/comment/exception/CommentErrorCode.java @@ -8,7 +8,8 @@ public enum CommentErrorCode implements ErrorCode { COMMENT_UPDATE_NOT_ALLOWED("C002", HttpStatus.FORBIDDEN, "본인의 댓글만 수정할 수 있습니다."), COMMENT_DELETE_NOT_ALLOWED("C003", HttpStatus.FORBIDDEN, "본인의 댓글만 삭제할 수 있습니다."), COMMENT_INVALID_DIRECTION("C004", HttpStatus.BAD_REQUEST, "올바르지 않은 정렬 방식입니다."), - COMMENT_ALREADY_WRITTEN("C005", HttpStatus.BAD_REQUEST, "이미 댓글을 작성했습니다. 댓글은 하나만 작성할 수 있습니다.") + COMMENT_ALREADY_WRITTEN("C005", HttpStatus.BAD_REQUEST, "이미 댓글을 작성했습니다. 댓글은 하나만 작성할 수 있습니다."), + COMMENT_SAME_GENDER_ONLY("C006", HttpStatus.BAD_REQUEST, "이성간 댓글을 작성할 수 없습니다."), ; private final String code; diff --git a/src/main/java/econo/buddybridge/comment/exception/CommentSameGenderOnlyException.java b/src/main/java/econo/buddybridge/comment/exception/CommentSameGenderOnlyException.java new file mode 100644 index 0000000..8ab94f8 --- /dev/null +++ b/src/main/java/econo/buddybridge/comment/exception/CommentSameGenderOnlyException.java @@ -0,0 +1,12 @@ +package econo.buddybridge.comment.exception; + +import econo.buddybridge.common.exception.BusinessException; + +public class CommentSameGenderOnlyException extends BusinessException { + + public static final BusinessException EXCEPTION = new CommentSameGenderOnlyException(); + + private CommentSameGenderOnlyException() { + super(CommentErrorCode.COMMENT_SAME_GENDER_ONLY); + } +} diff --git a/src/main/java/econo/buddybridge/comment/service/CommentService.java b/src/main/java/econo/buddybridge/comment/service/CommentService.java index 84d8a86..ba018ed 100644 --- a/src/main/java/econo/buddybridge/comment/service/CommentService.java +++ b/src/main/java/econo/buddybridge/comment/service/CommentService.java @@ -1,8 +1,5 @@ package econo.buddybridge.comment.service; -import static econo.buddybridge.common.consts.BuddyBridgeStatic.COMMENT_NOTIFICATION_MESSAGE; -import static econo.buddybridge.common.consts.BuddyBridgeStatic.getCommentNotificationUrl; - import econo.buddybridge.comment.dto.CommentCustomPage; import econo.buddybridge.comment.dto.CommentReqDto; import econo.buddybridge.comment.dto.MyPageCommentCustomPage; @@ -11,6 +8,7 @@ import econo.buddybridge.comment.exception.CommentDeleteNotAllowedException; import econo.buddybridge.comment.exception.CommentInvalidDirectionException; import econo.buddybridge.comment.exception.CommentNotFoundException; +import econo.buddybridge.comment.exception.CommentSameGenderOnlyException; import econo.buddybridge.comment.exception.CommentUpdateNotAllowedException; import econo.buddybridge.comment.repository.CommentRepository; import econo.buddybridge.member.entity.Member; @@ -27,6 +25,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static econo.buddybridge.common.consts.BuddyBridgeStatic.COMMENT_NOTIFICATION_MESSAGE; +import static econo.buddybridge.common.consts.BuddyBridgeStatic.getCommentNotificationUrl; + @Service @RequiredArgsConstructor public class CommentService { @@ -62,6 +63,10 @@ public Long createComment(CommentReqDto commentReqDto, Long postId, Long memberI Member member = memberService.findMemberByIdOrThrow(memberId); Post post = postService.findPostByIdOrThrow(postId); + if (post.getGender() != member.getGender()) { + throw CommentSameGenderOnlyException.EXCEPTION; + } + // 기존에 댓글을 작성한 적이 있는지 확인하고 있다면 댓글 작성 불가 if (commentRepository.existsByPostAndAuthor(post, member)) { throw CommentAlreadyWrittenException.EXCEPTION; diff --git a/src/main/java/econo/buddybridge/post/dto/PostReqDto.java b/src/main/java/econo/buddybridge/post/dto/PostReqDto.java index 8d4f15c..5290c2b 100644 --- a/src/main/java/econo/buddybridge/post/dto/PostReqDto.java +++ b/src/main/java/econo/buddybridge/post/dto/PostReqDto.java @@ -11,9 +11,10 @@ import econo.buddybridge.post.entity.ScheduleType; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Builder; + import java.time.LocalDateTime; import java.time.LocalTime; -import lombok.Builder; @Builder public record PostReqDto( @@ -43,13 +44,14 @@ public record PostReqDto( @NotNull(message = "게시글 종류를 선택해주세요. TAKER or GIVER") PostType postType, - + @NotNull(message = "봉사 시작 시간을 입력해주세요.") LocalTime assistanceStartTime, @NotNull(message = "봉사 종료 시간을 입력해주세요.") LocalTime assistanceEndTime, + // Todo : 모집 인원 제거 @NotNull(message = "모집 인원을 입력해주세요.") Integer headcount ) {