Skip to content

Commit

Permalink
[FEAT] 성별이 다를 경우 댓글 생성 제한 (#217)
Browse files Browse the repository at this point in the history
* feat(Comment): 댓글 작성시 성별이 다를 경우 댓글 생성 거부

* refactor(CommentService): 성별 확인 분기 순서 변경

* refactor(CommentService): 성별 확인 != 대신 equals 사용

* refactor(CommentService): equals 대신 != 사용

* refactor(CommentService): 필요없는 () 제거
  • Loading branch information
injae-348 authored Nov 27, 2024
1 parent 61e55f0 commit b28b236
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/econo/buddybridge/post/dto/PostReqDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
) {
Expand Down

0 comments on commit b28b236

Please sign in to comment.