generated from pricelees/issue-pr-template
<!-- 제목 양식 --> <!-- [이슈번호] 작업 요약 (예시: [#10] Gitea 템플릿 생성) --> ## 📝 관련 이슈 및 PR **PR과 관련된 이슈 번호** - #28 ## ✨ 작업 내용 <!-- 어떤 작업을 했는지 알려주세요! --> - 프론트엔드, 백엔드 쿠버네티스 환경 배포(ArgoCD 이용) - Helm 차트는 private repository에 업로드 ## 🧪 테스트 <!-- 어떤 테스트를 생각했고 진행했는지 알려주세요! --> - 배포 환경에서 기능 정상 동작 확인 ## 📚 참고 자료 및 기타 <!-- 참고한 자료, 또는 논의할 사항이 있다면 알려주세요! --> Reviewed-on: #29 Co-authored-by: pricelees <priceelees@gmail.com> Co-committed-by: pricelees <priceelees@gmail.com>
77 lines
2.6 KiB
Kotlin
77 lines
2.6 KiB
Kotlin
package roomescape.reservation.infrastructure.persistence
|
|
|
|
import org.springframework.data.jpa.domain.Specification
|
|
import roomescape.member.infrastructure.persistence.MemberEntity
|
|
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
|
import roomescape.time.infrastructure.persistence.TimeEntity
|
|
import java.time.LocalDate
|
|
|
|
class ReservationSearchSpecification(
|
|
private var spec: Specification<ReservationEntity> = Specification { _, _, _ -> null }
|
|
) {
|
|
fun sameThemeId(themeId: Long?): ReservationSearchSpecification = andIfNotNull(themeId?.let {
|
|
Specification { root, _, cb ->
|
|
cb.equal(root.get<ThemeEntity>("theme").get<Long>("id"), themeId)
|
|
}
|
|
})
|
|
|
|
fun sameMemberId(memberId: Long?): ReservationSearchSpecification = andIfNotNull(memberId?.let {
|
|
Specification { root, _, cb ->
|
|
cb.equal(root.get<MemberEntity>("member").get<Long>("id"), memberId)
|
|
}
|
|
})
|
|
|
|
fun sameTimeId(timeId: Long?): ReservationSearchSpecification = andIfNotNull(timeId?.let {
|
|
Specification { root, _, cb ->
|
|
cb.equal(root.get<TimeEntity>("time").get<Long>("id"), timeId)
|
|
}
|
|
})
|
|
|
|
fun sameDate(date: LocalDate?): ReservationSearchSpecification = andIfNotNull(date?.let {
|
|
Specification { root, _, cb ->
|
|
cb.equal(root.get<LocalDate>("date"), date)
|
|
}
|
|
})
|
|
|
|
fun confirmed(): ReservationSearchSpecification = andIfNotNull { root, _, cb ->
|
|
cb.or(
|
|
cb.equal(
|
|
root.get<ReservationStatus>("status"),
|
|
ReservationStatus.CONFIRMED
|
|
),
|
|
cb.equal(
|
|
root.get<ReservationStatus>("status"),
|
|
ReservationStatus.CONFIRMED_PAYMENT_REQUIRED
|
|
)
|
|
)
|
|
}
|
|
|
|
fun waiting(): ReservationSearchSpecification = andIfNotNull { root, _, cb ->
|
|
cb.equal(
|
|
root.get<ReservationStatus>("status"),
|
|
ReservationStatus.WAITING
|
|
)
|
|
}
|
|
|
|
fun dateStartFrom(dateFrom: LocalDate?): ReservationSearchSpecification = andIfNotNull(dateFrom?.let {
|
|
Specification { root, _, cb ->
|
|
cb.greaterThanOrEqualTo(root.get("date"), dateFrom)
|
|
}
|
|
})
|
|
|
|
fun dateEndAt(dateTo: LocalDate?): ReservationSearchSpecification = andIfNotNull(dateTo?.let {
|
|
Specification { root, _, cb ->
|
|
cb.lessThanOrEqualTo(root.get("date"), dateTo)
|
|
}
|
|
})
|
|
|
|
fun build(): Specification<ReservationEntity> {
|
|
return this.spec
|
|
}
|
|
|
|
private fun andIfNotNull(condition: Specification<ReservationEntity>?): ReservationSearchSpecification {
|
|
condition?.let { this.spec = this.spec.and(condition) }
|
|
return this
|
|
}
|
|
}
|