Skip to content

Commit

Permalink
[FEAT] 주문 검색 필터링 보내는분, 받는분, 주문번호 필터링 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokbeom00 committed Jan 14, 2025
1 parent 87d1a98 commit 4771a00
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,21 @@ public ResponseEntity<OrderCursorResponseDto> searchFieldPositionByCursor(
@RequestParam(required = false) final LocalDate deliveryDate,
@RequestParam(required = false) final String productName,
@RequestParam(required = false) final String deliveryStatus,
@RequestParam(required = false) Long cursorOrderId
@RequestParam(required = false) Long cursorOrderId,
@RequestParam(required = false) final String senderName,
@RequestParam(required = false) final String recipientName,
@RequestParam(required = false) final Integer orderNumber
) {

return ResponseEntity.ok(ordersService.searchOrderByCursor(
orderReceivedDate,
deliveryDate,
productName,
deliveryStatus,
cursorOrderId
cursorOrderId,
senderName,
recipientName,
orderNumber
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rootandfruit.server.api.domain.DeliveryStatus;
import com.rootandfruit.server.api.domain.Orders;
import jakarta.persistence.criteria.CriteriaBuilder.In;
import java.time.LocalDate;
import java.util.List;

Expand All @@ -10,5 +11,6 @@ List<Orders> searchOrders(LocalDate orderReceivedDate, LocalDate deliveryDate, S
DeliveryStatus deliveryStatus);

List<Orders> searchOrdersWithCursor(LocalDate orderReceivedDate, LocalDate deliveryDate, String productName,
DeliveryStatus deliveryStatus, Long cursorOrderId);
DeliveryStatus deliveryStatus, Long cursorOrderId, String senderName,
String recipientName, Integer orderNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public List<Orders> searchOrders(LocalDate orderReceivedDate, LocalDate delivery

@Override
public List<Orders> searchOrdersWithCursor(LocalDate orderReceivedDate, LocalDate deliveryDate, String productName,
DeliveryStatus deliveryStatus, Long cursorOrderId) {
DeliveryStatus deliveryStatus, Long cursorOrderId, String senderName,
String recipientName, Integer orderNumber) {
int limit = 50;
JPAQuery<Orders> query = queryFactory
.selectFrom(orders)
Expand All @@ -55,15 +56,28 @@ public List<Orders> searchOrdersWithCursor(LocalDate orderReceivedDate, LocalDat
ltDeliveryDate(deliveryDate),
eqProductName(productName),
eqDeliveryStatus(deliveryStatus),
cursorCondition(cursorOrderId) // 커서 조건
cursorCondition(cursorOrderId),
eqSenderName(senderName),
eqRecipientName(recipientName),
eqOrderNumber(orderNumber)
)
.orderBy(orders.id.desc())
.limit(limit);
System.out.println("========================");
System.out.println(query.toString());
return query.fetch();
}

private BooleanExpression eqSenderName(String senderName) {
return senderName != null ? QDeliveryInfo.deliveryInfo.senderName.eq(senderName) : null;
}

private BooleanExpression eqRecipientName(String recipientName) {
return recipientName != null ? QDeliveryInfo.deliveryInfo.recipientName.eq(recipientName) : null;
}

private BooleanExpression eqOrderNumber(Integer orderNumber) {
return orderNumber != null ? orders.orderNumber.eq(orderNumber) : null;
}

private BooleanExpression cursorCondition(Long cursorOrderId) {
return cursorOrderId != null ? orders.id.lt(cursorOrderId) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,18 @@ public void patchNote(NoteRequestDto noteRequestDto) {
}

@Transactional(readOnly = true)
public OrderCursorResponseDto searchOrderByCursor(LocalDate orderReceivedDate, LocalDate deliveryDate, String productName,
String deliveryStatus, Long cursorOrderId) {
public OrderCursorResponseDto searchOrderByCursor(LocalDate orderReceivedDate, LocalDate deliveryDate,
String productName,
String deliveryStatus, Long cursorOrderId, String senderName,
String recipientName, Integer orderNumber) {
DeliveryStatus status = null;
if (deliveryStatus != null) {
status = DeliveryStatus.fromString(deliveryStatus);
}

// 주문 목록 조회
List<Orders> orderList = ordersRepository.searchOrdersWithCursor(orderReceivedDate, deliveryDate, productName, status, cursorOrderId);
List<Orders> orderList = ordersRepository.searchOrdersWithCursor(orderReceivedDate, deliveryDate, productName,
status, cursorOrderId, senderName, recipientName, orderNumber);

// 배송 정보별로 주문을 그룹화
Map<Long, List<Orders>> ordersByDeliveryInfo = orderList.stream()
Expand Down

0 comments on commit 4771a00

Please sign in to comment.