-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GETP-143 test: 피플 목록 조회 컨트롤러 단위 테스트 및 API 문서 작성 (#67)
* GETP-143 feat: 페이지 객체 DTO `PageResponse` 구현 * GETP-143 test: 피플 목록 조회 컨트롤러 단위 테스트 및 API 문서 작성
- Loading branch information
Showing
12 changed files
with
215 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
operation::/get-card-people-page/get-card-people-page[snippets="http-request,query-parameters,http-response,response-fields-data"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/es/princip/getp/global/domain/dto/response/PageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package es.princip.getp.global.domain.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Sort; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class PageResponse<T> { | ||
private final List<T> content; | ||
private final PageInfo pageInfo; | ||
|
||
private PageResponse(List<T> content, PageInfo pageInfo) { | ||
this.content = content; | ||
this.pageInfo = pageInfo; | ||
} | ||
|
||
public static <T> PageResponse<T> from(Page<T> page) { | ||
PageInfo pageInfo = PageInfo.builder() | ||
.totalPages(page.getTotalPages()) | ||
.totalElements(page.getTotalElements()) | ||
.size(page.getSize()) | ||
.number(page.getNumber()) | ||
.numberOfElements(page.getNumberOfElements()) | ||
.first(page.isFirst()) | ||
.last(page.isLast()) | ||
.empty(page.isEmpty()) | ||
.sort(page.getSort()) | ||
.build(); | ||
return new PageResponse<>(page.getContent(), pageInfo); | ||
} | ||
|
||
@Getter | ||
static class SortInfo { | ||
private final String property; | ||
private final String direction; | ||
|
||
public SortInfo(Sort.Order order) { | ||
this.property = order.getProperty(); | ||
this.direction = order.getDirection().name(); | ||
} | ||
} | ||
|
||
@Getter | ||
static class PageInfo { | ||
private final int totalPages; | ||
private final long totalElements; | ||
private final int size; | ||
private final int number; | ||
private final int numberOfElements; | ||
private final boolean first; | ||
private final boolean last; | ||
private final boolean empty; | ||
private final SortInfo sort; | ||
|
||
@Builder | ||
public PageInfo( | ||
int totalPages, | ||
long totalElements, | ||
int size, | ||
int number, | ||
int numberOfElements, | ||
boolean first, | ||
boolean last, | ||
boolean empty, | ||
Sort sort | ||
) { | ||
this.totalPages = totalPages; | ||
this.totalElements = totalElements; | ||
this.size = size; | ||
this.number = number; | ||
this.numberOfElements = numberOfElements; | ||
this.first = first; | ||
this.last = last; | ||
this.empty = empty; | ||
this.sort = sort.stream().map(SortInfo::new).findFirst().orElse(null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package es.princip.getp.global.util; | ||
|
||
public class StringUtil { | ||
|
||
public static String camelToSnake(String camelCase) { | ||
if (camelCase == null || camelCase.isEmpty()) { | ||
return camelCase; | ||
} | ||
|
||
String regex = "([a-z])([A-Z]+)"; | ||
String replacement = "$1_$2"; | ||
|
||
return camelCase.replaceAll(regex, replacement); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/java/es/princip/getp/global/support/PageResponseDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package es.princip.getp.global.support; | ||
|
||
import org.springframework.restdocs.payload.FieldDescriptor; | ||
|
||
import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; | ||
|
||
public class PageResponseDescriptor { | ||
|
||
public static FieldDescriptor[] pageResponseFieldDescriptors() { | ||
return new FieldDescriptor[] { | ||
getDescriptor("pageInfo.totalPages", "전체 페이지 수"), | ||
getDescriptor("pageInfo.totalElements", "전체 요소 수"), | ||
getDescriptor("pageInfo.size", "페이지 크기"), | ||
getDescriptor("pageInfo.number", "현재 페이지 번호"), | ||
getDescriptor("pageInfo.numberOfElements", "현재 페이지 요소 수"), | ||
getDescriptor("pageInfo.first", "첫 페이지 여부"), | ||
getDescriptor("pageInfo.last", "마지막 페이지 여부"), | ||
getDescriptor("pageInfo.empty", "비어있는 페이지 여부"), | ||
getDescriptor("pageInfo.sort.property", "정렬 속성"), | ||
getDescriptor("pageInfo.sort.direction", "정렬 방향") | ||
}; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...est/resources/org/springframework/restdocs/templates/asciidoctor/query-parameters.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|=== | ||
|Parameter|Description|Optional|Default | ||
|
||
{{#parameters}} | ||
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
|{{#tableCellContent}}{{#optional}}Yes{{/optional}}{{^optional}}No{{/optional}}{{/tableCellContent}} | ||
|{{#tableCellContent}}{{default}}{{/tableCellContent}} | ||
|
||
{{/parameters}} | ||
|=== |