Skip to content

Commit bde087c

Browse files
committed
feat(community): community-comment boardId request 필드 -> Pathvariable
1 parent d0e5806 commit bde087c

11 files changed

+36
-38
lines changed

src/main/java/com/somemore/community/dto/request/CommunityCommentCreateRequestDto.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
1515
@Builder
1616
public record CommunityCommentCreateRequestDto(
17-
@Schema(description = "커뮤니티 게시글 ID", example = "33")
18-
@NotNull(message = "게시글 ID는 필수 값입니다.")
19-
Long communityBoardId,
2017
@Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.")
2118
@NotBlank(message = "댓글 내용은 필수 값입니다.")
2219
String content,
2320
@Schema(description = "부모 댓글 ID", example = "1234", nullable = true)
2421
@Nullable
2522
Long parentCommentId
2623
) {
27-
public CommunityComment toEntity(UUID writerId) {
24+
public CommunityComment toEntity(UUID writerId, Long communityBoardId) {
2825
return CommunityComment.builder()
2926
.communityBoardId(communityBoardId)
3027
.writerId(writerId)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public class CreateCommunityCommentService implements CreateCommunityCommentUseC
2424
private final CommunityCommentRepository communityCommentRepository;
2525

2626
@Override
27-
public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId) {
28-
CommunityComment communityComment = requestDto.toEntity(writerId);
27+
public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId, Long communityBoardId) {
28+
CommunityComment communityComment = requestDto.toEntity(writerId, communityBoardId);
2929

30-
validateCommunityBoardExists(communityComment.getCommunityBoardId());
30+
validateCommunityBoardExists(communityBoardId);
3131

3232
if (requestDto.parentCommentId() != null) {
3333
validateParentCommentExists(communityComment.getParentCommentId());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DeleteCommunityCommentService implements DeleteCommunityCommentUseC
2020
private final CommunityCommentRepository communityCommentRepository;
2121

2222
@Override
23-
public void deleteCommunityComment(UUID writerId, Long id) {
23+
public void deleteCommunityComment(UUID writerId, Long id, Long communityBoardId) {
2424

2525
CommunityComment communityComment = getCommunityCommentById(id);
2626

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public class UpdateCommunityCommentService implements UpdateCommunityCommentUseC
2323
private final CommunityBoardRepository communityBoardRepository;
2424

2525
@Override
26-
public void updateCommunityComment(CommunityCommentUpdateRequestDto requestDto, Long communityCommentId, UUID writerId) {
26+
public void updateCommunityComment(CommunityCommentUpdateRequestDto requestDto, Long communityCommentId, UUID writerId, Long communityBoardId) {
2727

2828
CommunityComment communityComment = getCommunityCommentById(communityCommentId);
2929

30-
validateCommunityBoardExists(communityComment.getCommunityBoardId());
30+
validateCommunityBoardExists(communityBoardId);
3131

3232
validateWriter(communityComment, writerId);
3333

src/main/java/com/somemore/community/usecase/comment/CreateCommunityCommentUseCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
public interface CreateCommunityCommentUseCase {
88
Long createCommunityComment(
99
CommunityCommentCreateRequestDto requestDto,
10-
UUID writerId);
10+
UUID writerId,
11+
Long communityBoardId);
1112
}

src/main/java/com/somemore/community/usecase/comment/DeleteCommunityCommentUseCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import java.util.UUID;
44

55
public interface DeleteCommunityCommentUseCase {
6-
void deleteCommunityComment(UUID writerId, Long id);
6+
void deleteCommunityComment(UUID writerId, Long id, Long communityBoardId);
77
}

src/main/java/com/somemore/community/usecase/comment/UpdateCommunityCommentUseCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public interface UpdateCommunityCommentUseCase {
88
void updateCommunityComment(
99
CommunityCommentUpdateRequestDto requestDto,
1010
Long communityCommentId,
11-
UUID writerId);
11+
UUID writerId,
12+
Long communityBoardId);
1213
}

src/test/java/com/somemore/community/service/comment/CommunityCommentQueryServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void getCommentsByCommunityBoardId() {
8888
@Test
8989
void doesNotFind() {
9090
//given
91-
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, replyId);
91+
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, replyId, boardId);
9292

9393
//when
9494
Page<CommunityCommentResponseDto> comments = communityCommentQueryService.getCommunityCommentsByBoardId(boardId, 0);
@@ -105,7 +105,7 @@ void doesNotFind() {
105105
void getCommentsByCommunityBoardIdWithDeletedComment() {
106106

107107
//given
108-
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, commentId);
108+
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, commentId, boardId);
109109
//when
110110
Page<CommunityCommentResponseDto> comments = communityCommentQueryService.getCommunityCommentsByBoardId(boardId, 0);
111111

src/test/java/com/somemore/community/service/comment/CreateCommunityCommentServiceTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ void createCommunityCommentWithDto() {
5959

6060
//given
6161
CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto.builder()
62-
.communityBoardId(boardId)
6362
.content("커뮤니티 댓글 테스트 내용")
6463
.parentCommentId(null)
6564
.build();
6665

6766
//when
68-
Long commentId = createCommunityCommentService.createCommunityComment(dto, writerId);
67+
Long commentId = createCommunityCommentService.createCommunityComment(dto, writerId, boardId);
6968

7069
//then
7170
Optional<CommunityComment> communityComment = communityCommentRepository.findById(commentId);
@@ -83,21 +82,19 @@ void createCommunityCommentRelyWithDto() {
8382

8483
//given
8584
CommunityCommentCreateRequestDto commentDto = CommunityCommentCreateRequestDto.builder()
86-
.communityBoardId(boardId)
8785
.content("커뮤니티 댓글 테스트 내용")
8886
.parentCommentId(null)
8987
.build();
9088

91-
Long commentId = createCommunityCommentService.createCommunityComment(commentDto, writerId);
89+
Long commentId = createCommunityCommentService.createCommunityComment(commentDto, writerId, boardId);
9290

9391
CommunityCommentCreateRequestDto replyDto = CommunityCommentCreateRequestDto.builder()
94-
.communityBoardId(boardId)
9592
.content("커뮤니티 대댓글 테스트 내용")
9693
.parentCommentId(commentId)
9794
.build();
9895

9996
//when
100-
Long replyCommentId = createCommunityCommentService.createCommunityComment(replyDto, writerId);
97+
Long replyCommentId = createCommunityCommentService.createCommunityComment(replyDto, writerId, boardId);
10198

10299
//then
103100
Optional<CommunityComment> communityCommentReply = communityCommentRepository.findById(replyCommentId);
@@ -115,13 +112,12 @@ void createCommunityCommentReplyWithDeletedParentId() {
115112

116113
//given
117114
CommunityCommentCreateRequestDto replyDto = CommunityCommentCreateRequestDto.builder()
118-
.communityBoardId(boardId)
119115
.content("커뮤니티 대댓글 테스트 내용")
120116
.parentCommentId(2L)
121117
.build();
122118

123119
//when
124-
ThrowableAssert.ThrowingCallable callable = () -> createCommunityCommentService.createCommunityComment(replyDto, UUID.randomUUID());
120+
ThrowableAssert.ThrowingCallable callable = () -> createCommunityCommentService.createCommunityComment(replyDto, UUID.randomUUID(), boardId);
125121

126122
//then
127123
assertThatExceptionOfType(BadRequestException.class)
@@ -135,15 +131,14 @@ void createCommunityCommentWithDeletedBoardId() {
135131

136132
//given
137133
CommunityCommentCreateRequestDto commentDto = CommunityCommentCreateRequestDto.builder()
138-
.communityBoardId(boardId)
139134
.content("커뮤니티 댓글 테스트 내용")
140135
.parentCommentId(null)
141136
.build();
142137

143138
communityBoardRepository.deleteAllInBatch();
144139

145140
//when
146-
ThrowableAssert.ThrowingCallable callable = () -> createCommunityCommentService.createCommunityComment(commentDto, UUID.randomUUID());
141+
ThrowableAssert.ThrowingCallable callable = () -> createCommunityCommentService.createCommunityComment(commentDto, UUID.randomUUID(), boardId);
147142

148143
//then
149144
assertThatExceptionOfType(BadRequestException.class)

src/test/java/com/somemore/community/service/comment/DeleteCommunityCommentServiceTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DeleteCommunityCommentServiceTest extends IntegrationTestSupport {
3232
private CommunityBoardRepository communityBoardRepository;
3333

3434
private UUID writerId;
35-
private Long commentId;
35+
private Long commentId, boardId;
3636

3737
@BeforeEach
3838
void setUp() {
@@ -44,14 +44,14 @@ void setUp() {
4444
writerId = UUID.randomUUID();
4545

4646
CommunityBoard communityBoard = communityBoardRepository.save(boardDto.toEntity(writerId, "https://test.image/123"));
47+
boardId = communityBoard.getId();
4748

4849
CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto.builder()
49-
.communityBoardId(communityBoard.getId())
5050
.content("커뮤니티 댓글 테스트 내용")
5151
.parentCommentId(null)
5252
.build();
5353

54-
CommunityComment communityComment = communityCommentRepository.save(dto.toEntity(writerId));
54+
CommunityComment communityComment = communityCommentRepository.save(dto.toEntity(writerId, communityBoard.getId()));
5555

5656
commentId = communityComment.getId();}
5757

@@ -66,7 +66,7 @@ void deleteCommunityCommentWithId() {
6666

6767
//given
6868
//when
69-
deleteCommunityCommentService.deleteCommunityComment(writerId, commentId);
69+
deleteCommunityCommentService.deleteCommunityComment(writerId, commentId, boardId);
7070

7171
//then
7272
assertThat(communityCommentRepository.existsById(commentId)).isFalse();
@@ -77,10 +77,10 @@ void deleteCommunityCommentWithId() {
7777
void deleteCommunityCommentWithDeletedId() {
7878

7979
//given
80-
deleteCommunityCommentService.deleteCommunityComment(writerId, commentId);
80+
deleteCommunityCommentService.deleteCommunityComment(writerId, commentId, boardId);
8181

8282
//when
83-
ThrowableAssert.ThrowingCallable callable = () -> deleteCommunityCommentService.deleteCommunityComment(writerId, commentId);
83+
ThrowableAssert.ThrowingCallable callable = () -> deleteCommunityCommentService.deleteCommunityComment(writerId, commentId, boardId);
8484

8585
//then
8686
assertThatExceptionOfType(BadRequestException.class)
@@ -94,7 +94,7 @@ void deleteCommunityCommentWithNotWriterId() {
9494

9595
//given
9696
//when
97-
ThrowableAssert.ThrowingCallable callable = () -> deleteCommunityCommentService.deleteCommunityComment(UUID.randomUUID(), commentId);
97+
ThrowableAssert.ThrowingCallable callable = () -> deleteCommunityCommentService.deleteCommunityComment(UUID.randomUUID(), commentId, boardId);
9898

9999
//then
100100
assertThatExceptionOfType(BadRequestException.class)

0 commit comments

Comments
 (0)