File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
src/main/java/com/somemore/community/service/comment Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 22
33import com .somemore .community .domain .CommunityComment ;
44import com .somemore .community .dto .request .CommunityCommentCreateRequestDto ;
5+ import com .somemore .community .repository .board .CommunityBoardRepository ;
56import com .somemore .community .repository .comment .CommunityCommentRepository ;
67import com .somemore .community .usecase .comment .CreateCommunityCommentUseCase ;
78import com .somemore .global .exception .BadRequestException ;
1112
1213import java .util .UUID ;
1314
15+ import static com .somemore .global .exception .ExceptionMessage .NOT_EXISTS_COMMUNITY_BOARD ;
1416import static com .somemore .global .exception .ExceptionMessage .NOT_EXISTS_COMMUNITY_COMMENT ;
1517
1618@ RequiredArgsConstructor
1719@ Transactional
1820@ Service
1921public 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 ());
You can’t perform that action at this time.
0 commit comments