Skip to content

Commit

Permalink
Merge pull request #151 from Yanabada/feature/148
Browse files Browse the repository at this point in the history
판매 가능한 예약 조회 로직 수정
  • Loading branch information
Hwang-Kyu-Cheol authored Jan 23, 2024
2 parents 64f3f66 + b863f78 commit e29391d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package kr.co.fastcampus.yanabada.domain.accommodation.entity.enums;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum RoomCancelPolicy {
YNBD_1, YNBD_2, YNBD_3
YNBD_1(7L),
YNBD_2(6L),
YNBD_3(Long.MAX_VALUE),
;

private final long feeOccurrenceDuration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static kr.co.fastcampus.yanabada.domain.accommodation.entity.QAccommodation.accommodation;
import static kr.co.fastcampus.yanabada.domain.accommodation.entity.QRoom.room;
import static kr.co.fastcampus.yanabada.domain.accommodation.entity.enums.RoomCancelPolicy.YNBD_1;
import static kr.co.fastcampus.yanabada.domain.accommodation.entity.enums.RoomCancelPolicy.YNBD_2;
import static kr.co.fastcampus.yanabada.domain.order.entity.QOrder.order;
import static kr.co.fastcampus.yanabada.domain.order.entity.enums.OrderStatus.RESERVED;
import static kr.co.fastcampus.yanabada.domain.product.entity.QProduct.product;
Expand All @@ -10,6 +12,8 @@

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.ComparableExpression;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDate;
Expand All @@ -34,12 +38,13 @@ public List<Order> getSellableByMember(Member member) {

return queryFactory
.selectFrom(order)
.leftJoin(product).on(product.order.eq(order).and(containStatuses(ON_SALE, BOOKING)))
.leftJoin(product).on(product.order.eq(order), containStatuses(ON_SALE, BOOKING))
.join(order.room, room).fetchJoin()
.join(room.accommodation, accommodation).fetchJoin()
.where(
equalMember(member),
equalStatus(RESERVED)
equalStatus(RESERVED),
hasRoomCancelFee()
)
.groupBy(order)
.having(count.eq(ZERO_COUNT))
Expand Down Expand Up @@ -99,4 +104,30 @@ private BooleanExpression lessCheckInDate(LocalDate date) {

return order.checkInDate.lt(date);
}

private BooleanExpression hasRoomCancelFee() {
return new CaseBuilder()
.when(room.cancelPolicy.eq(YNBD_1)).then(hasRoomCancelFeeInYNBD_1())
.when(room.cancelPolicy.eq(YNBD_2)).then(hasRoomCancelFeeInYNBD_2())
.otherwise(true)
.eq(true);
}

private ComparableExpression<Boolean> hasRoomCancelFeeInYNBD_1() {
return new CaseBuilder()
.when(
order.checkInDate.loe(LocalDate.now().plusDays(YNBD_1.getFeeOccurrenceDuration()))
)
.then(true)
.otherwise(false);
}

private ComparableExpression<Boolean> hasRoomCancelFeeInYNBD_2() {
return new CaseBuilder()
.when(
order.checkInDate.loe(LocalDate.now().plusDays(YNBD_2.getFeeOccurrenceDuration()))
)
.then(true)
.otherwise(false);
}
}

0 comments on commit e29391d

Please sign in to comment.