-
Notifications
You must be signed in to change notification settings - Fork 0
fix(payment): paginate pending requests #48
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
base: main
Are you sure you want to change the base?
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,16 @@ | ||||||
| package com.comatching.item.domain.product.service; | ||||||
|
|
||||||
| import java.time.LocalDateTime; | ||||||
| import java.util.List; | ||||||
|
|
||||||
| import org.springframework.data.domain.PageRequest; | ||||||
| import org.springframework.data.domain.Pageable; | ||||||
| import org.springframework.data.domain.Sort; | ||||||
| import org.springframework.stereotype.Service; | ||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||
|
|
||||||
| import com.comatching.common.domain.enums.ItemRoute; | ||||||
| import com.comatching.common.dto.item.AddItemRequest; | ||||||
| import com.comatching.common.dto.response.PagingResponse; | ||||||
| import com.comatching.common.exception.BusinessException; | ||||||
| import com.comatching.item.domain.item.service.ItemService; | ||||||
| import com.comatching.item.domain.order.entity.Order; | ||||||
|
|
@@ -29,6 +32,8 @@ | |||||
| public class AdminPaymentServiceImpl implements AdminPaymentService { | ||||||
|
|
||||||
| private static final String EXPIRE_REASON = "AUTO_EXPIRED_BEFORE_ADMIN_DECISION"; | ||||||
| private static final int MAX_PENDING_REQUEST_PAGE_SIZE = 100; | ||||||
| private static final Sort DEFAULT_PENDING_REQUEST_SORT = Sort.by(Sort.Direction.DESC, "requestedAt"); | ||||||
|
|
||||||
| private final OrderRepository orderRepository; | ||||||
| private final OrderGrantLedgerRepository orderGrantLedgerRepository; | ||||||
|
|
@@ -40,11 +45,25 @@ public class AdminPaymentServiceImpl implements AdminPaymentService { | |||||
| private static final int PURCHASED_ITEM_EXPIRE_DAYS = 36500; | ||||||
|
|
||||||
| @Override | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly = true)
@OverrideReferences
|
||||||
| public List<PurchaseRequestDto> getPendingRequests() { | ||||||
| return orderRepository.findAllByStatusAndExpiresAtAfterOrderByRequestedAtDesc(OrderStatus.PENDING, LocalDateTime.now()) | ||||||
| .stream() | ||||||
| .map(PurchaseRequestDto::from) | ||||||
| .toList(); | ||||||
| public PagingResponse<PurchaseRequestDto> getPendingRequests(Pageable pageable) { | ||||||
| Pageable boundedPageable = toBoundedPageable(pageable); | ||||||
| return PagingResponse.from( | ||||||
| orderRepository.findAllByStatusAndExpiresAtAfter( | ||||||
| OrderStatus.PENDING, | ||||||
| LocalDateTime.now(), | ||||||
| boundedPageable | ||||||
| ).map(PurchaseRequestDto::from) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| private Pageable toBoundedPageable(Pageable pageable) { | ||||||
| if (pageable == null || pageable.isUnpaged()) { | ||||||
| return PageRequest.of(0, MAX_PENDING_REQUEST_PAGE_SIZE, DEFAULT_PENDING_REQUEST_SORT); | ||||||
| } | ||||||
|
|
||||||
| int pageSize = Math.min(pageable.getPageSize(), MAX_PENDING_REQUEST_PAGE_SIZE); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Sort sort = pageable.getSort().isSorted() ? pageable.getSort() : DEFAULT_PENDING_REQUEST_SORT; | ||||||
| return PageRequest.of(pageable.getPageNumber(), pageSize, sort); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
||||||
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.
MAX_PENDING_REQUEST_PAGE_SIZE와 같은 설정 값은 코드 내 상수로 관리하기보다
@ConfigurationProperties를 통해 외부 설정 파일(yml/properties)에서 관리하는 것을 권장합니다. 이를 통해 운영 환경에서 코드 수정 없이 상한선을 조정할 수 있어 유연성이 높아집니다.References