diff --git a/src/main/java/com/coolpeace/domain/coupon/repository/CouponRepositoryImpl.java b/src/main/java/com/coolpeace/domain/coupon/repository/CouponRepositoryImpl.java index 13464288..3018d8be 100644 --- a/src/main/java/com/coolpeace/domain/coupon/repository/CouponRepositoryImpl.java +++ b/src/main/java/com/coolpeace/domain/coupon/repository/CouponRepositoryImpl.java @@ -41,7 +41,9 @@ public CouponRepositoryImpl(JPAQueryFactory jpaQueryFactory) { @Override public Page 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) { @@ -75,11 +77,11 @@ public Page findAllCoupons(Long memberId, Long accommodationId, SearchCo JPAQuery couponJPAQuery = jpaQueryFactory.selectFrom(coupon) .leftJoin(coupon.couponRooms, couponRooms).fetchJoin() .leftJoin(couponRooms.room, room).fetchJoin() - .where(coupon.accommodation.id.eq(accommodationId)) .where(searchCouponPredicate); JPAQuery 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 coupons = Objects.requireNonNull(getQuerydsl()).applyPagination(pageable, couponJPAQuery).fetch(); @@ -162,31 +164,31 @@ public List 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 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 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 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(); } } diff --git a/src/main/java/com/coolpeace/global/exception/ErrorCode.java b/src/main/java/com/coolpeace/global/exception/ErrorCode.java index bacf7301..74a16165 100644 --- a/src/main/java/com/coolpeace/global/exception/ErrorCode.java +++ b/src/main/java/com/coolpeace/global/exception/ErrorCode.java @@ -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, "노출 날짜 기간 이후에만 종료할 수 있습니다."),