|
1 | 1 | package com.back.domain.post.post.dto; |
2 | 2 |
|
3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import lombok.Data; |
4 | 5 | import org.springframework.data.domain.Page; |
| 6 | +import org.springframework.security.core.parameters.P; |
5 | 7 |
|
6 | 8 | import java.util.List; |
7 | 9 |
|
8 | | -public record PostPagingResponse( |
9 | | - @Schema(description = "게시글 목록") |
10 | | - List<PostDto> posts, |
11 | | - @Schema(description = "현재 페이지 (0부터 시작)") |
12 | | - int currentPage, |
13 | | - @Schema(description = "총 페이지") |
14 | | - int totalPage, |
15 | | - @Schema(description = "총 개수") |
16 | | - long totalElements, |
17 | | - @Schema(description = "다음 페이지 존재 여부") |
18 | | - boolean hasNext |
19 | | -) { |
| 10 | +@Data |
| 11 | +public class PostPagingResponse{ |
| 12 | + |
| 13 | + @Schema(description = "게시글 목록") |
| 14 | + List<PostDto> posts; |
| 15 | + @Schema(description = "현재 페이지 (0부터 시작)") |
| 16 | + int currentPage; |
| 17 | + @Schema(description = "총 페이지") |
| 18 | + int totalPage; |
| 19 | + @Schema(description = "총 개수") |
| 20 | + long totalElements; |
| 21 | + @Schema(description = "다음 페이지 존재 여부") |
| 22 | + boolean hasNext; |
20 | 23 |
|
21 | 24 | public static PostPagingResponse from(Page<PostDto> page) { |
22 | | - return new PostPagingResponse( |
23 | | - page.getContent(), |
24 | | - page.getNumber(), |
25 | | - page.getTotalPages(), |
26 | | - page.getTotalElements(), |
27 | | - page.hasNext() |
28 | | - ); |
| 25 | + PostPagingResponse postPagingResponse = new PostPagingResponse(); |
| 26 | + postPagingResponse.setPosts(page.getContent()); |
| 27 | + postPagingResponse.setCurrentPage(page.getNumber()); |
| 28 | + postPagingResponse.setTotalPage(page.getTotalPages()); |
| 29 | + postPagingResponse.setTotalElements(page.getTotalElements()); |
| 30 | + postPagingResponse.setHasNext(page.hasNext()); |
| 31 | + |
| 32 | + return postPagingResponse; |
29 | 33 | } |
30 | 34 |
|
31 | 35 | } |
|
0 commit comments