diff --git a/src/main/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCase.kt b/src/main/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCase.kt index 47de6665..26322056 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCase.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCase.kt @@ -20,7 +20,7 @@ class QueryReservationByHomeBaseUseCase( val homeBases = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period) return homeBases.map { - reservationPort.queryReservationByHomeBase(it)?.let { reservation -> + reservationPort.queryReservationByHomeBaseId(it.id)?.let { reservation -> val users = userService.queryAllUserById(reservation.userIds) ReservationResponse.of( diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationService.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationService.kt index 157567c7..13af770c 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationService.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationService.kt @@ -7,7 +7,7 @@ import java.util.* interface QueryReservationService { fun queryReservationById(id: UUID): Reservation - fun queryReservationByHomeBase(homeBase: HomeBase): Reservation? + fun queryReservationByHomeBaseId(homeBaseId: Long): Reservation? fun queryAllReservationByHomeBaseIn(homeBases: List): List fun queryAllReservation(): List fun countReservationByHomeBase(homeBase: HomeBase): Int diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationServiceImpl.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationServiceImpl.kt index c8a6d625..39279ce9 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationServiceImpl.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/service/QueryReservationServiceImpl.kt @@ -15,8 +15,8 @@ class QueryReservationServiceImpl( override fun queryReservationById(id: UUID): Reservation = queryReservationPort.queryReservationById(id) ?: throw ReservationNotFoundException() - override fun queryReservationByHomeBase(homeBase: HomeBase): Reservation? = - queryReservationPort.queryReservationByHomeBase(homeBase) + override fun queryReservationByHomeBaseId(homeBaseId: Long): Reservation? = + queryReservationPort.queryReservationByHomeBaseId(homeBaseId) override fun queryAllReservationByHomeBaseIn(homeBases: List): List = queryReservationPort.queryAllReservationByHomeBaseIn(homeBases) diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/spi/QueryReservationPort.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/spi/QueryReservationPort.kt index c737347b..7956f134 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/spi/QueryReservationPort.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/spi/QueryReservationPort.kt @@ -7,7 +7,7 @@ import java.util.UUID interface QueryReservationPort { fun queryReservationById(id: UUID): Reservation? - fun queryReservationByHomeBase(homeBase: HomeBase): Reservation? + fun queryReservationByHomeBaseId(homeBaseId: Long): Reservation? fun queryAllReservationByHomeBaseIn(homeBases: List): List fun queryAllReservations(): List fun countReservationByHomeBase(homeBase: HomeBase): Int diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/validator/ReservationValidatorImpl.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/validator/ReservationValidatorImpl.kt index 9121f7e6..42762b27 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/application/validator/ReservationValidatorImpl.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/application/validator/ReservationValidatorImpl.kt @@ -8,21 +8,19 @@ import java.time.LocalDateTime @Component class ReservationValidatorImpl : ReservationValidator { + // 오전 8시 10분부터 오후 8시 30분까지만 예약 가능 override fun validateReservationTime(currentTime: LocalDateTime, period: Int) { val hour = currentTime.hour val minute = currentTime.minute - /* - 오전 8시 10분부터 오후 8시 30분까지만 예약 가능 - */ if (hour < 8 || (hour == 8 && minute < 10) || hour > 20 || (hour == 20 && minute > 30)) throw NotReserveHomeBaseHourException() } + // 금요일, 토요일, 일요일은 예약 불가능 override fun validateReservationDay(currentTime: LocalDateTime): DayOfWeek { val dayOfWeek = currentTime.dayOfWeek - // 금요일, 토요일, 일요일은 예약 불가능 if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) throw NotReserveHomeBaseHourException() diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/ReservationPersistenceAdapter.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/ReservationPersistenceAdapter.kt index 0b812609..f6253899 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/ReservationPersistenceAdapter.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/ReservationPersistenceAdapter.kt @@ -35,8 +35,8 @@ class ReservationPersistenceAdapter( override fun queryReservationById(id: UUID) = reservationMapper.toDomain(reservationRepository.findByIdOrNull(id)) - override fun queryReservationByHomeBase(homeBase: HomeBase): Reservation? = - reservationMapper.toDomain(reservationRepository.findByHomeBase(homeBaseMapper.toEntity(homeBase))) + override fun queryReservationByHomeBaseId(homeBaseId: Long): Reservation? = + reservationMapper.toDomain(reservationRepository.findByHomeBaseId(homeBaseId)) override fun queryAllReservationByHomeBaseIn(homeBases: List): List = reservationRepository.findAllByHomeBaseIn(homeBases.map { homeBaseMapper.toEntity(it) }) diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/entity/ReservationJpaEntity.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/entity/ReservationJpaEntity.kt index ce5e93de..f9b760cf 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/entity/ReservationJpaEntity.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/entity/ReservationJpaEntity.kt @@ -1,11 +1,19 @@ package team.msg.hiv2.domain.reservation.persistence.entity +import javax.persistence.CollectionTable +import javax.persistence.Column +import javax.persistence.ElementCollection +import javax.persistence.Entity +import javax.persistence.FetchType +import javax.persistence.Index +import javax.persistence.JoinColumn +import javax.persistence.OneToOne +import javax.persistence.Table +import org.hibernate.annotations.OnDelete +import org.hibernate.annotations.OnDeleteAction import team.msg.hiv2.domain.homebase.persistence.entity.HomeBaseJpaEntity import team.msg.hiv2.global.entity.BaseUuidEntity import java.util.* -import javax.persistence.* -import org.hibernate.annotations.OnDelete -import org.hibernate.annotations.OnDeleteAction @Entity @Table(name = "reservation") @@ -26,8 +34,11 @@ class ReservationJpaEntity( @JoinColumn(name = "reservation_id") @OnDelete(action = OnDeleteAction.CASCADE) @Column(columnDefinition = "BINARY(16)", name = "user_id") - @ElementCollection - @CollectionTable(name = "users", joinColumns = [JoinColumn(name = "reservation_id")]) + @ElementCollection(fetch = FetchType.LAZY) + @CollectionTable( + name = "users", + joinColumns = [JoinColumn(name = "reservation_id")] + ) val userIds: MutableList ) : BaseUuidEntity(id) \ No newline at end of file diff --git a/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/repository/ReservationRepository.kt b/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/repository/ReservationRepository.kt index 5564e947..09f5107c 100644 --- a/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/repository/ReservationRepository.kt +++ b/src/main/kotlin/team/msg/hiv2/domain/reservation/persistence/repository/ReservationRepository.kt @@ -9,7 +9,7 @@ import javax.persistence.LockModeType.* interface ReservationRepository : JpaRepository { @EntityGraph(attributePaths = ["homeBase"]) - fun findByHomeBase(homeBase: HomeBaseJpaEntity): ReservationJpaEntity? + fun findByHomeBaseId(homeBaseId: Long): ReservationJpaEntity? @EntityGraph(attributePaths = ["homeBase"]) fun findAllByHomeBaseIn(homeBases: List): List @Modifying diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 8e594eb4..0c0b19a3 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -3,9 +3,6 @@ - - - @@ -14,7 +11,7 @@ - + diff --git a/src/test/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCaseTest.kt b/src/test/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCaseTest.kt index f0dbfdc4..5c8204b3 100644 --- a/src/test/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCaseTest.kt +++ b/src/test/kotlin/team/msg/hiv2/domain/homebase/application/usecase/QueryReservationByHomeBaseUseCaseTest.kt @@ -125,7 +125,7 @@ class QueryReservationByHomeBaseUseCaseTest { given(queryHomeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)) .willReturn(listOf(homeBaseStub)) - given(queryReservationPort.queryReservationByHomeBase(homeBaseStub)) + given(queryReservationPort.queryReservationByHomeBaseId(homeBaseId)) .willReturn(reservationStub) given(userService.queryAllUserById(listOf(userId1, userId2)))