diff --git a/src/main/java/kr/bb/store/domain/coupon/repository/CouponRepositoryCustomImpl.java b/src/main/java/kr/bb/store/domain/coupon/repository/CouponRepositoryCustomImpl.java index db74115..b874317 100644 --- a/src/main/java/kr/bb/store/domain/coupon/repository/CouponRepositoryCustomImpl.java +++ b/src/main/java/kr/bb/store/domain/coupon/repository/CouponRepositoryCustomImpl.java @@ -54,7 +54,7 @@ public List findAllValidateCouponsByStoreId(Long storeId, LocalDate now) .selectFrom(coupon) .where( coupon.store.id.eq(storeId), - isCouponUnexpired(now), + isValidDate(now), coupon.isDeleted.isFalse() ) .fetch(); @@ -82,7 +82,7 @@ public List findStoreCouponsForUser(Long userId, Long .from(coupon) .where( coupon.store.id.eq(storeId), - isCouponUnexpired(now), + isValidDate(now), coupon.isDeleted.isFalse() ) .fetch(); @@ -106,7 +106,7 @@ public List findAvailableCoupons(Long totalAmount, Lo coupon.store.id.eq(storeId), issuedCoupon.id.userId.eq(userId), issuedCoupon.isUsed.isFalse(), - isCouponUnexpired(now), + isValidDate(now), coupon.isDeleted.isFalse() ) .fetch(); @@ -129,7 +129,7 @@ public List findMyValidCoupons(Long userId, LocalDate now) { .where( issuedCoupon.id.userId.eq(userId), issuedCoupon.isUsed.isFalse(), - isCouponUnexpired(now), + isValidDate(now), coupon.isDeleted.isFalse() ) .fetch(); @@ -145,14 +145,15 @@ public Integer findMyValidCouponCount(Long userId, LocalDate now) { .where( issuedCoupon.id.userId.eq(userId), issuedCoupon.isUsed.isFalse(), - isCouponUnexpired(now), + isValidDate(now), coupon.isDeleted.isFalse() ) .fetchFirst()); } - private BooleanExpression isCouponUnexpired(LocalDate now) { - return coupon.endDate.after(now).or(coupon.endDate.eq(now)); + private BooleanExpression isValidDate(LocalDate now) { + return coupon.startDate.before(now).or(coupon.startDate.eq(now)) + .and(coupon.endDate.after(now).or(coupon.endDate.eq(now))); } }