forked from prgrms-be-devcourse/BE-04-NaBMart
-
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.
Merge pull request #4 from pushedrumex/refactor
refactor: 상품 정렬 로직에 불필요한 과정 제거
- Loading branch information
Showing
11 changed files
with
115 additions
and
289 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
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
30 changes: 4 additions & 26 deletions
30
src/main/java/com/prgrms/nabmart/domain/item/service/request/FindHotItemsCommand.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 |
---|---|---|
@@ -1,33 +1,11 @@ | ||
package com.prgrms.nabmart.domain.item.service.request; | ||
|
||
import com.prgrms.nabmart.domain.item.ItemSortType; | ||
import java.util.Objects; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
public record FindHotItemsCommand( | ||
Long lastIdx, | ||
Long lastItemId, | ||
PageRequest pageRequest, | ||
ItemSortType sortType | ||
) { | ||
public record FindHotItemsCommand(PageRequest pageRequest) { | ||
|
||
private static final int DEFAULT_PAGE_NUMBER = 0; | ||
|
||
public static FindHotItemsCommand of(Long lastIdx, Long lastItemId, int pageSize, | ||
String sortType) { | ||
if (isFirstIdx(lastIdx)) { | ||
lastIdx = Long.parseLong(String.valueOf(Integer.MAX_VALUE)); | ||
if (Objects.equals(sortType, "LOWEST_AMOUNT") || Objects.equals(sortType, "NEW")) { | ||
lastIdx = Long.MIN_VALUE; | ||
} | ||
} | ||
|
||
ItemSortType itemSortType = ItemSortType.from(sortType); | ||
PageRequest pageRequest = PageRequest.of(DEFAULT_PAGE_NUMBER, pageSize); | ||
return new FindHotItemsCommand(lastIdx, lastItemId, pageRequest, itemSortType); | ||
} | ||
|
||
private static boolean isFirstIdx(Long previousItemId) { | ||
return previousItemId < 0; | ||
public static FindHotItemsCommand of(int page, int size) { | ||
PageRequest pageRequest = PageRequest.of(page, size); | ||
return new FindHotItemsCommand(pageRequest); | ||
} | ||
} |
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
Oops, something went wrong.