Skip to content

Commit aba6126

Browse files
committed
refactor: 댓글 부분 구조 변경
1 parent b8b3ef7 commit aba6126

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

src/main/java/com/threestar/trainus/domain/comment/controller/CommentController.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414

1515
import com.threestar.trainus.domain.comment.dto.CommentCreateRequestDto;
1616
import com.threestar.trainus.domain.comment.dto.CommentPageResponseDto;
17+
import com.threestar.trainus.domain.comment.dto.CommentPageWrapperDto;
1718
import com.threestar.trainus.domain.comment.dto.CommentResponseDto;
19+
import com.threestar.trainus.domain.comment.mapper.CommentMapper;
1820
import com.threestar.trainus.domain.comment.service.CommentService;
1921
import com.threestar.trainus.global.unit.BaseResponse;
22+
import com.threestar.trainus.global.unit.PagedResponse;
2023

2124
import io.swagger.v3.oas.annotations.Operation;
2225
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -45,13 +48,14 @@ public ResponseEntity<BaseResponse<CommentResponseDto>> createComment(@PathVaria
4548

4649
@GetMapping("/{lessonId}")
4750
@Operation(summary = "댓글 조회", description = "레슨 ID에 해당되는 댓글들을 조회합니다.")
48-
public ResponseEntity<BaseResponse<CommentPageResponseDto>> readAll(@PathVariable Long lessonId,
51+
public ResponseEntity<PagedResponse<CommentPageWrapperDto>> readAll(@PathVariable Long lessonId,
4952
@RequestParam("page") int page,
5053
@RequestParam("pageSize") int pageSize) {
5154
int correctPage = Math.max(page, 1);
5255
int correctPageSize = Math.max(1, Math.max(pageSize, pageSizeLimit));
53-
return BaseResponse.ok("댓글 조회 성공", commentService.readAll(lessonId, correctPage, correctPageSize),
54-
HttpStatus.OK);
56+
CommentPageResponseDto commentsInfo = commentService.readAll(lessonId, correctPage, correctPageSize);
57+
CommentPageWrapperDto comments = CommentMapper.toCommentPageWrapperDto(commentsInfo);
58+
return PagedResponse.ok("댓글 조회 성공", comments, commentsInfo.getCount(), HttpStatus.OK);
5559
}
5660

5761
@DeleteMapping("/{commentId}")

src/main/java/com/threestar/trainus/domain/comment/dto/CommentPageResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
public class CommentPageResponseDto {
1111

1212
private List<CommentResponseDto> comments;
13-
private Long count;
13+
private Integer count;
1414
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.threestar.trainus.domain.comment.dto;
2+
3+
import java.util.List;
4+
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@Builder
10+
public class CommentPageWrapperDto {
11+
private List<CommentResponseDto> comments;
12+
}

src/main/java/com/threestar/trainus/domain/comment/mapper/CommentMapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44

55
import com.threestar.trainus.domain.comment.dto.CommentPageResponseDto;
6+
import com.threestar.trainus.domain.comment.dto.CommentPageWrapperDto;
67
import com.threestar.trainus.domain.comment.dto.CommentResponseDto;
78
import com.threestar.trainus.domain.comment.entity.Comment;
89

@@ -22,10 +23,16 @@ public static CommentResponseDto toCommentResponseDto(Comment comment) {
2223
.build();
2324
}
2425

25-
public static CommentPageResponseDto toCommentPageResponseDto(List<CommentResponseDto> comments, Long count) {
26+
public static CommentPageResponseDto toCommentPageResponseDto(List<CommentResponseDto> comments, Integer count) {
2627
return CommentPageResponseDto.builder()
2728
.comments(comments)
2829
.count(count)
2930
.build();
3031
}
32+
33+
public static CommentPageWrapperDto toCommentPageWrapperDto(CommentPageResponseDto commentPageResponseDto) {
34+
return CommentPageWrapperDto.builder()
35+
.comments(commentPageResponseDto.getComments())
36+
.build();
37+
}
3138
}

src/main/java/com/threestar/trainus/domain/comment/repository/CommentRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
2323
@Query(value = """
2424
select count(*) from ( select comment_id from comments where lesson_id = :lessonId limit :limit) t
2525
""", nativeQuery = true)
26-
Long count(@Param("lessonId") Long lessonId, @Param("limit") int limit);
26+
Integer count(@Param("lessonId") Long lessonId, @Param("limit") int limit);
2727

2828
@Query(value = """
2929
select count(*) from (select comment_id from comments where lesson_id = :lessonId and parent_comment_id = :parentCommentId limit :limit) t

0 commit comments

Comments
 (0)