Skip to content

Commit

Permalink
feat: (#249) 휴무표 작성 기간 exists 쿼리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 committed Dec 22, 2022
1 parent ecc8dfb commit e6a600f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.comit.simtong.domain.holiday.spi

import team.comit.simtong.domain.holiday.model.HolidayPeriod
import java.time.LocalDate
import java.util.UUID

/**
Expand All @@ -15,4 +16,6 @@ interface QueryHolidayPeriodPort {

fun queryHolidayPeriodByYearAndMonthAndSpotId(year: Int, month: Int, spotId: UUID) : HolidayPeriod?

fun existsHolidayPeriodByDateAndSpotId(date: LocalDate, spotId: UUID) : Boolean

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package team.comit.simtong.persistence.holiday

import team.comit.simtong.persistence.holiday.entity.QHolidayPeriodJpaEntity.holidayPeriodJpaEntity as holidayPeriod
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Component
import team.comit.simtong.domain.holiday.model.HolidayPeriod
import team.comit.simtong.domain.holiday.spi.HolidayPeriodPort
import team.comit.simtong.persistence.holiday.entity.HolidayPeriodJpaEntity
import team.comit.simtong.persistence.holiday.mapper.HolidayPeriodMapper
import team.comit.simtong.persistence.holiday.repository.HolidayPeriodJpaRepository
import java.time.LocalDate
import java.util.UUID

/**
Expand All @@ -20,7 +23,8 @@ import java.util.UUID
@Component
class HolidayPeriodPersistenceAdapter(
private val holidayPeriodMapper: HolidayPeriodMapper,
private val holidayPeriodJpaRepository: HolidayPeriodJpaRepository
private val holidayPeriodJpaRepository: HolidayPeriodJpaRepository,
private val queryFactory: JPAQueryFactory
) : HolidayPeriodPort {

override fun queryHolidayPeriodByYearAndMonthAndSpotId(year: Int, month: Int, spotId: UUID): HolidayPeriod? {
Expand All @@ -33,5 +37,14 @@ class HolidayPeriodPersistenceAdapter(
).let(holidayPeriodMapper::toDomain)
}

override fun existsHolidayPeriodByDateAndSpotId(date: LocalDate, spotId: UUID): Boolean {
return queryFactory.selectFrom(holidayPeriod)
.where(
holidayPeriod.id.spotId.eq(spotId),
holidayPeriod.startAt.after(date),
holidayPeriod.endAt.before(date)
)
.fetchOne() != null
}

}

0 comments on commit e6a600f

Please sign in to comment.