Skip to content

Commit

Permalink
[feature] findAllCoupons 메소드 수정
Browse files Browse the repository at this point in the history
설명:
- #216 을 참고하세요.
  • Loading branch information
tkddn204 committed Jan 27, 2024
1 parent 22571aa commit 6b5e250
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public CouponRepositoryImpl(JPAQueryFactory jpaQueryFactory) {
@Override
public Page<Coupon> findAllCoupons(Long memberId, Long accommodationId, SearchCouponParams params, PageRequest pageable) {
// 검색 필터링
BooleanBuilder searchCouponPredicate = new BooleanBuilder(coupon.member.id.eq(memberId));
BooleanBuilder searchCouponPredicate = new BooleanBuilder(
coupon.accommodation.id.eq(accommodationId).and(coupon.member.id.eq(memberId))
);

// 쿠폰 상태
if (params.status() != null) {
Expand Down Expand Up @@ -75,11 +77,11 @@ public Page<Coupon> findAllCoupons(Long memberId, Long accommodationId, SearchCo
JPAQuery<Coupon> couponJPAQuery = jpaQueryFactory.selectFrom(coupon)
.leftJoin(coupon.couponRooms, couponRooms).fetchJoin()
.leftJoin(couponRooms.room, room).fetchJoin()
.where(coupon.accommodation.id.eq(accommodationId))
.where(searchCouponPredicate);

JPAQuery<Long> totalQuery = jpaQueryFactory.select(coupon.count()).from(coupon)
.where(coupon.accommodation.id.eq(accommodationId))
.leftJoin(coupon.couponRooms, couponRooms).fetchJoin()
.leftJoin(couponRooms.room, room).fetchJoin()
.where(searchCouponPredicate);

List<Coupon> coupons = Objects.requireNonNull(getQuerydsl()).applyPagination(pageable, couponJPAQuery).fetch();
Expand Down Expand Up @@ -162,31 +164,31 @@ public List<Coupon> expiration3days(Long memberId, Long accommodationId) {
.where(coupon.member.id.eq(memberId)
.and(coupon.accommodation.id.eq(accommodationId))
.and(coupon.couponStatus.ne(DELETED))
.and(coupon.exposureEndDate.between(LocalDate.now().minusDays(1),
LocalDate.now().plusDays(4))))
.and(coupon.exposureEndDate.between(LocalDate.now().minusDays(1),
LocalDate.now().plusDays(4))))
.fetch();
}

@Override
public List<Coupon> findAllByExposureDate(Accommodation accommodation, LocalDate localDate) {
return jpaQueryFactory.selectFrom(coupon)
.where(coupon.accommodation.eq(accommodation)
.and(coupon.exposureStartDate.before(localDate))
.and(coupon.exposureEndDate.after(localDate))).fetch();
.where(coupon.accommodation.eq(accommodation)
.and(coupon.exposureStartDate.before(localDate))
.and(coupon.exposureEndDate.after(localDate))).fetch();
}

@Override
public List<Coupon> endExposureCoupons(LocalDate nowDate) {
return jpaQueryFactory.selectFrom(coupon)
.where(coupon.couponStatus.ne(CouponStatusType.DELETED)
.and(coupon.exposureEndDate.before(nowDate))).fetch();
.where(coupon.couponStatus.ne(CouponStatusType.DELETED)
.and(coupon.exposureEndDate.before(nowDate))).fetch();
}

@Override
public List<Coupon> startExposureCoupons(LocalDate nowDate) {
return jpaQueryFactory.selectFrom(coupon)
.where(coupon.couponStatus.eq(CouponStatusType.EXPOSURE_WAIT)
.and((coupon.exposureStartDate.before(nowDate))
.or(coupon.exposureStartDate.eq(nowDate)))).fetch();
.where(coupon.couponStatus.eq(CouponStatusType.EXPOSURE_WAIT)
.and((coupon.exposureStartDate.before(nowDate))
.or(coupon.exposureStartDate.eq(nowDate)))).fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum ErrorCode {
COUPON_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 쿠폰의 정보를 찾을 수 없습니다."),
COUPON_ACCESS_DENIED(HttpStatus.FORBIDDEN, "해당 쿠폰에 대한 편집 권한이 없습니다."),
COUPON_UPDATE_LIMIT_EXPOSURE_STATE(HttpStatus.BAD_REQUEST, "노출 여부 변경은 노출 ON과 노출 OFF만 가능합니다."),
INVALID_COUPON_STATE_OUTSIDE_EXPOSURE_DATE(HttpStatus.BAD_REQUEST, "노출 날짜 기간 이내에만 ON/OFF일 수 있습니다."),
INVALID_COUPON_STATE_OUTSIDE_EXPOSURE_DATE(HttpStatus.BAD_REQUEST, "노출 날짜 기간 이내에만 ON/OFF일 수 있습니다."),
INVALID_COUPON_STATE_WAIT_EXPOSURE_DATE(HttpStatus.BAD_REQUEST, "노출 날짜 기간 이전에만 대기중일 수 있습니다."),
INVALID_COUPON_STATE_END_EXPOSURE_DATE(HttpStatus.BAD_REQUEST, "노출 날짜 기간 이후에만 종료할 수 있습니다."),

Expand Down

0 comments on commit 6b5e250

Please sign in to comment.