-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 요청 파라미터에 기본 정렬 조건 설정 및 페이지네이션 요청 값 검증 #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| @Schema(description = "실시간 경매장 정렬 필드", enumAsRef = true) | ||
| public enum RealtimeSortField { | ||
| DATE_AUCTION_EXPIRE("dateAuctionExpire", "경매 만료 일시"), | ||
| DATE_REGISTER("dateRegister", "등록 일시"), | ||
| DATE_AUCTION_REGISTER("dateRegister", "등록 일시"), | ||
| AUCTION_PRICE_PER_UNIT("auctionPricePerUnit", "개당 가격"), | ||
|
Comment on lines
11
to
14
|
||
| ITEM_NAME("itemName", "아이템 이름"); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,20 +12,23 @@ | |
| @Schema(description = "페이지 요청 파라미터") | ||
| public record PageRequestDto( | ||
| @Schema(description = "요청할 페이지 번호 (1부터 시작)", example = "1") @Min(1) Integer page, | ||
| @Schema(description = "페이지당 항목 수", example = "20") @Min(1) @Max(100) Integer size, | ||
| @Schema(description = "페이지당 항목 수 (10~50)", example = "20") @Min(10) @Max(50) Integer size, | ||
| @Schema( | ||
| description = "정렬 필드 (dateAuctionBuy, auctionPricePerUnit, itemName)", | ||
| example = "dateAuctionBuy") | ||
| SortField sortBy, | ||
| @Schema(description = "정렬 방향 (ASC, DESC)", example = "DESC") SortDirection direction) { | ||
| private static final int DEFAULT_PAGE = 1; | ||
| private static final int DEFAULT_SIZE = 20; | ||
| private static final int MIN_SIZE = 10; | ||
| private static final int MAX_SIZE = 50; | ||
| private static final SortField DEFAULT_SORT_BY = SortField.DATE_AUCTION_BUY; | ||
| private static final SortDirection DEFAULT_DIRECTION = SortDirection.DESC; | ||
|
|
||
| public Pageable toPageable() { | ||
| int resolvedPage = this.page != null ? this.page - 1 : DEFAULT_PAGE - 1; | ||
| int resolvedSize = this.size != null ? this.size : DEFAULT_SIZE; | ||
| resolvedSize = Math.max(MIN_SIZE, Math.min(MAX_SIZE, resolvedSize)); | ||
| SortField resolvedSortBy = this.sortBy != null ? this.sortBy : DEFAULT_SORT_BY; | ||
|
Comment on lines
28
to
32
|
||
| SortDirection resolvedDirection = | ||
| this.direction != null ? this.direction : DEFAULT_DIRECTION; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,8 @@ | |
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import until.the.eternity.auctionhistory.domain.repository.AuctionHistoryRepositoryPort; | ||
| import until.the.eternity.common.exception.CustomException; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfoId; | ||
| import until.the.eternity.iteminfo.domain.exception.ItemInfoExceptionCode; | ||
| import until.the.eternity.iteminfo.domain.repository.ItemInfoRepositoryPort; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.request.ItemInfoSearchRequest; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemCategoryResponse; | ||
|
|
@@ -53,7 +51,6 @@ public List<ItemInfoResponse> findBySubCategory(String subCategory) { | |
|
|
||
| public Page<ItemInfoResponse> findAllDetail( | ||
| ItemInfoSearchRequest searchRequest, Pageable pageable) { | ||
| validateTopCategory(searchRequest); | ||
| Page<ItemInfo> itemInfoPage = | ||
| itemInfoRepository.searchWithPagination(searchRequest, pageable); | ||
| return itemInfoPage.map(ItemInfoResponse::from); | ||
|
Comment on lines
52
to
56
|
||
|
|
@@ -62,7 +59,6 @@ public Page<ItemInfoResponse> findAllDetail( | |
| public List<ItemInfoSummaryResponse> findAllSummary( | ||
| ItemInfoSearchRequest searchRequest, | ||
| org.springframework.data.domain.Sort.Direction direction) { | ||
| validateTopCategory(searchRequest); | ||
| // direction을 Pageable로 변환 | ||
| Pageable pageable = | ||
| org.springframework.data.domain.PageRequest.of( | ||
|
|
@@ -73,12 +69,6 @@ public List<ItemInfoSummaryResponse> findAllSummary( | |
| return ItemInfoSummaryResponse.from(itemInfos); | ||
| } | ||
|
|
||
| private void validateTopCategory(ItemInfoSearchRequest searchRequest) { | ||
| if (searchRequest.topCategory() == null || searchRequest.topCategory().isBlank()) { | ||
| throw new CustomException(ItemInfoExceptionCode.TOP_CATEGORY_REQUIRED); | ||
| } | ||
| } | ||
|
|
||
| @Transactional | ||
| public ItemInfoSyncResponse syncItemInfoFromAuctionHistory() { | ||
| log.info("Starting to sync ItemInfo from AuctionHistory"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| package until.the.eternity.iteminfo.interfaces.rest.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| @Schema(description = "아이템 정보 검색 요청 파라미터") | ||
| public record ItemInfoSearchRequest( | ||
| @Schema(description = "아이템 이름", example = "나뭇가지") String name, | ||
| @Schema(description = "하위 카테고리", example = "한손검") String subCategory, | ||
| @Schema(description = "상위 카테고리 (필수)", example = "무기", required = true) | ||
| @NotBlank(message = "상위 카테고리(topCategory)는 필수 파라미터입니다.") | ||
| String topCategory) {} | ||
| @Schema(description = "상위 카테고리 (선택)", example = "무기") String topCategory) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RealtimePageRequestDto의 Schema 설명에 정렬 필드로dateAuctionRegister가 노출되어 있는데, 실제 정렬 property 및RealtimeSortField.from()변환은dateRegister를 사용합니다. 현재 상태에서는 문서에 나온 값으로 요청하면 기본 정렬로 fallback 되어 사용자가 의도한 정렬이 적용되지 않습니다. 허용되는 query parameter 값 목록을 실제 변환/정렬과 동일하게 맞춰 주세요(또는 alias 지원).