Skip to content

Commit 0f63ec6

Browse files
committed
feat(community): CommunityComment 생성 시 게시글 검증 로직 추가
1 parent cc82066 commit 0f63ec6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/com/somemore/community/service/comment/CreateCommunityCommentService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.somemore.community.domain.CommunityComment;
44
import com.somemore.community.dto.request.CommunityCommentCreateRequestDto;
5+
import com.somemore.community.repository.board.CommunityBoardRepository;
56
import com.somemore.community.repository.comment.CommunityCommentRepository;
67
import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase;
78
import com.somemore.global.exception.BadRequestException;
@@ -11,24 +12,34 @@
1112

1213
import java.util.UUID;
1314

15+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_BOARD;
1416
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT;
1517

1618
@RequiredArgsConstructor
1719
@Transactional
1820
@Service
1921
public class CreateCommunityCommentService implements CreateCommunityCommentUseCase {
2022

23+
private final CommunityBoardRepository communityBoardRepository;
2124
private final CommunityCommentRepository communityCommentRepository;
2225

2326
@Override
2427
public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId) {
2528
CommunityComment communityComment = requestDto.toEntity(writerId);
2629

30+
validateCommunityBoardExists(communityComment.getCommunityBoardId());
31+
2732
validateParentCommentExists(communityComment.getParentCommentId());
2833

2934
return communityCommentRepository.save(communityComment).getId();
3035
}
3136

37+
private void validateCommunityBoardExists(Long communityBoardId) {
38+
if (communityBoardRepository.doesNotExistById(communityBoardId)) {
39+
throw new BadRequestException(NOT_EXISTS_COMMUNITY_BOARD.getMessage());
40+
}
41+
}
42+
3243
private void validateParentCommentExists(Long parentCommentId) {
3344
if (parentCommentId != null && !communityCommentRepository.existsById(parentCommentId)) {
3445
throw new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage());

0 commit comments

Comments
 (0)