Skip to content

Commit 3151a8b

Browse files
committed
feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가
1 parent 10a0dbb commit 3151a8b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import com.somemore.community.dto.request.CommunityCommentCreateRequestDto;
55
import com.somemore.community.repository.comment.CommunityCommentRepository;
66
import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase;
7+
import com.somemore.global.exception.BadRequestException;
78
import lombok.RequiredArgsConstructor;
89
import org.springframework.stereotype.Service;
910
import org.springframework.transaction.annotation.Transactional;
1011

1112
import java.util.UUID;
1213

14+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT;
15+
1316
@RequiredArgsConstructor
1417
@Transactional
1518
@Service
@@ -18,12 +21,15 @@ public class CreateCommunityCommentService implements CreateCommunityCommentUseC
1821
private final CommunityCommentRepository communityCommentRepository;
1922

2023
@Override
21-
public Long CreateCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId, Long parentCommunityId) {
24+
public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId) {
2225

23-
CommunityComment communityComment = requestDto.toEntity(writerId, parentCommunityId);
26+
CommunityComment communityComment = requestDto.toEntity(writerId);
2427

25-
communityCommentRepository.save(communityComment);
28+
if (communityComment.getParentCommentId() != null) {
29+
communityCommentRepository.findById(communityComment.getParentCommentId())
30+
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage()));
31+
}
2632

27-
return communityComment.getId();
33+
return communityCommentRepository.save(communityComment).getId();
2834
}
2935
}

src/main/java/com/somemore/global/exception/ExceptionMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum ExceptionMessage {
1111
NOT_EXISTS_CENTER("존재하지 않는 기관 ID 입니다."),
1212
NOT_EXISTS_COMMUNITY_BOARD("존재하지 않는 게시글 입니다."),
1313
UNAUTHORIZED_COMMUNITY_BOARD("해당 게시글에 권한이 없습니다."),
14+
NOT_EXISTS_COMMUNITY_COMMENT("존재하지 않는 댓글 입니다."),
1415
NOT_EXISTS_LOCATION("존재하지 않는 위치 ID 입니다."),
1516
NOT_EXISTS_RECRUIT_BOARD("존재하지 않는 봉사 모집글 ID 입니다."),
1617
UNAUTHORIZED_RECRUIT_BOARD("자신이 작성한 봉사 모집글이 아닙니다."),

0 commit comments

Comments
 (0)