Skip to content

Commit 9f3333b

Browse files
committed
test(community): CommunityComment 삭제 Usecase 추가 및 Service 구현
1 parent 370911c commit 9f3333b

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.somemore.community.service.comment;
2+
3+
import com.somemore.community.domain.CommunityComment;
4+
import com.somemore.community.repository.comment.CommunityCommentRepository;
5+
import com.somemore.community.usecase.comment.DeleteCommunityCommentUseCase;
6+
import com.somemore.global.exception.BadRequestException;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.stereotype.Service;
9+
import org.springframework.transaction.annotation.Transactional;
10+
11+
import java.util.UUID;
12+
13+
import static com.somemore.global.exception.ExceptionMessage.*;
14+
15+
@RequiredArgsConstructor
16+
@Transactional
17+
@Service
18+
public class DeleteCommunityCommentService implements DeleteCommunityCommentUseCase {
19+
20+
private final CommunityCommentRepository communityCommentRepository;
21+
22+
@Override
23+
public void deleteCommunityComment(UUID writerId, Long id) {
24+
25+
CommunityComment communityComment = getCommunityBoardById(id);
26+
27+
validateWriter(communityComment, writerId);
28+
29+
communityComment.markAsDeleted();
30+
31+
communityCommentRepository.save(communityComment);
32+
}
33+
34+
private CommunityComment getCommunityBoardById(Long id) {
35+
return communityCommentRepository.findById(id)
36+
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage()));
37+
}
38+
39+
private void validateWriter(CommunityComment communityComment, UUID writerId) {
40+
if (communityComment.isWriter(writerId)) {
41+
return;
42+
}
43+
44+
throw new BadRequestException(UNAUTHORIZED_COMMUNITY_COMMENT.getMessage());
45+
}
46+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.somemore.community.usecase.comment;
2+
3+
import java.util.UUID;
4+
5+
public interface DeleteCommunityCommentUseCase {
6+
void deleteCommunityComment(UUID writerId, Long id);
7+
}

0 commit comments

Comments
 (0)