Skip to content

Commit

Permalink
feat : 내 정산 내역 조회 API Pagination (issue WeblingCafe#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingj7235 committed Jul 26, 2023
1 parent d0ea6ab commit 2b38954
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import webling.coffee.backend.domain.order.dto.request.SettlementRequestDto;
import webling.coffee.backend.domain.order.service.SettlementFacade;
import webling.coffee.backend.global.annotation.AuthRequired;
Expand Down Expand Up @@ -71,9 +68,9 @@ public ResponseEntity<SuccessResponse> settlementAllBySearchOptions(final @NotNu
"""
)
@AuthRequired
@PostMapping("/me")
@GetMapping("/me")
public ResponseEntity<SuccessResponse> settlementMeBySearchOptions (final @NotNull @Parameter(hidden = true) @AuthUser UserAuthentication authentication,
final @NotNull @RequestBody SettlementRequestDto.RegDate request) {
final @NotNull @RequestBody SettlementRequestDto.BaseField request) {

return SuccessResponse.toResponseEntity(
OrderSuccessCode.SETTLEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.time.LocalDateTime;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class SettlementRequestDto {

@Getter
Expand All @@ -18,15 +21,24 @@ public static class Search {
private String username;
private String userNickname;
@JsonUnwrapped
private RegDate regDate;
private BaseField baseField;
}

@Getter
@Setter
@NoArgsConstructor
@Schema(name = "SettlementRequestRegDate")
public static class RegDate {
@Schema(name = "SettlementRequestBaseField")
public static class BaseField {

private static final int MAX_SIZE = 200;

private Integer page = 1;
private Integer size = 10;
private LocalDateTime fromDate;
private LocalDateTime toDate;

public long getOffSet () {
return (long) (max(1, page) -1) * min(size, MAX_SIZE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<SettlementResponseDto.User> settlementAllBySearchOptions(final @NotN
}

public SettlementResponseDto.User settlementMeBySearchOptions(final @NotNull Long userId,
final @NotNull SettlementRequestDto.RegDate request) {
final @NotNull SettlementRequestDto.BaseField request) {

User user = userService.findByIdAndIsAvailableTrue(userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public interface QueryUserRepository {

List<User> settlementAllBySearchOptions(final @NotNull SettlementRequestDto.Search request);

User settlementMeBySearchOptions(final @NotNull User user, final @NotNull SettlementRequestDto.RegDate request);
User settlementMeBySearchOptions(final @NotNull User user, final @NotNull SettlementRequestDto.BaseField request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Optional;

import static webling.coffee.backend.domain.coupon.entity.QCoupon.coupon;
import static webling.coffee.backend.domain.order.entity.QOrder.order;
import static webling.coffee.backend.domain.order.entity.QOrderCart.orderCart;
import static webling.coffee.backend.domain.user.entity.QUser.user;
Expand Down Expand Up @@ -75,7 +74,7 @@ public List<User> settlementAllBySearchOptions(final @NotNull SettlementRequestD
.fetchJoin()
.where(
order.orderStatus.eq(OrderStatus.COMPLETED),
regDateBetween(request.getRegDate()),
regDateBetween(request.getBaseField()),
usernameLike(request.getUsername()),
nicknameLike(request.getUserNickname())
)
Expand All @@ -84,7 +83,7 @@ public List<User> settlementAllBySearchOptions(final @NotNull SettlementRequestD
}

@Override
public User settlementMeBySearchOptions(final User entity, final SettlementRequestDto.RegDate request) {
public User settlementMeBySearchOptions(final User entity, final SettlementRequestDto.BaseField request) {
return jpaQueryFactory.selectFrom(user)
.leftJoin(user.orderCart, orderCart)
.fetchJoin()
Expand All @@ -95,11 +94,13 @@ public User settlementMeBySearchOptions(final User entity, final SettlementReque
order.orderStatus.eq(OrderStatus.COMPLETED),
regDateBetween(request)
)
.limit(request.getSize())
.offset(request.getOffSet())
.fetchFirst()
;
}

private BooleanExpression regDateBetween (final @NotNull SettlementRequestDto.RegDate request) {
private BooleanExpression regDateBetween (final @NotNull SettlementRequestDto.BaseField request) {

if (request.getFromDate() == null && request.getToDate() == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<User> settlementAllBySearchOptions(final @NotNull SettlementRequestD

@Transactional(readOnly = true)
public User settlementMeBySearchOptions(final @NotNull User user,
final @NotNull SettlementRequestDto.RegDate request) {
final @NotNull SettlementRequestDto.BaseField request) {
return userRepository.settlementMeBySearchOptions(user, request);
}

Expand Down

0 comments on commit 2b38954

Please sign in to comment.