Skip to content

Commit

Permalink
✏️ 시작일과 종료일 기준으로 쿠폰의 유효성 판단해 사용자에게 유효한 쿠폰만 보여줌
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty1434 committed Jan 19, 2024
1 parent 44b911d commit b810dea
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Coupon> findAllValidateCouponsByStoreId(Long storeId, LocalDate now)
.selectFrom(coupon)
.where(
coupon.store.id.eq(storeId),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand Down Expand Up @@ -82,7 +82,7 @@ public List<CouponWithIssueStatusDto> findStoreCouponsForUser(Long userId, Long
.from(coupon)
.where(
coupon.store.id.eq(storeId),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand All @@ -106,7 +106,7 @@ public List<CouponWithAvailabilityDto> 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();
Expand All @@ -129,7 +129,7 @@ public List<CouponDto> findMyValidCoupons(Long userId, LocalDate now) {
.where(
issuedCoupon.id.userId.eq(userId),
issuedCoupon.isUsed.isFalse(),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand All @@ -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)));
}

}

0 comments on commit b810dea

Please sign in to comment.