Skip to content

Commit ed06d86

Browse files
committed
test(community): communityComment 수정 Usecase 및 Service 생성
1 parent 493e63f commit ed06d86

File tree

2 files changed

+57
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)