generated from pricelees/issue-pr-template
[#30] 코드 구조 개선 #31
@ -1,22 +1,12 @@
|
|||||||
package roomescape.theme.business.domain
|
package roomescape.theme.business.domain
|
||||||
|
|
||||||
import roomescape.time.web.TimeWithAvailabilityResponse
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
|
|
||||||
class TimeWithAvailability(
|
class TimeWithAvailability(
|
||||||
private val timeId: Long,
|
val timeId: Long,
|
||||||
private val startAt: LocalTime,
|
val startAt: LocalTime,
|
||||||
private val date: LocalDate,
|
val date: LocalDate,
|
||||||
private val themeId: Long,
|
val themeId: Long,
|
||||||
private val isReservable: Boolean
|
val isReservable: Boolean
|
||||||
) {
|
)
|
||||||
fun toResponse() = TimeWithAvailabilityResponse(
|
|
||||||
id = timeId,
|
|
||||||
startAt = startAt,
|
|
||||||
isAvailable = isReservable
|
|
||||||
)
|
|
||||||
|
|
||||||
// for test
|
|
||||||
fun canReserve(): Boolean = isReservable
|
|
||||||
}
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package roomescape.time.business
|
|||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import roomescape.theme.business.domain.TimeWithAvailability
|
|
||||||
import roomescape.time.implement.TimeFinder
|
import roomescape.time.implement.TimeFinder
|
||||||
import roomescape.time.implement.TimeWriter
|
import roomescape.time.implement.TimeWriter
|
||||||
import roomescape.time.infrastructure.persistence.TimeEntity
|
import roomescape.time.infrastructure.persistence.TimeEntity
|
||||||
@ -39,9 +38,17 @@ class TimeService(
|
|||||||
fun findTimesWithAvailability(date: LocalDate, themeId: Long): TimeWithAvailabilityListResponse {
|
fun findTimesWithAvailability(date: LocalDate, themeId: Long): TimeWithAvailabilityListResponse {
|
||||||
log.info { "[TimeService.findTimesWithAvailability] 시작: date=$date, themeId=$themeId" }
|
log.info { "[TimeService.findTimesWithAvailability] 시작: date=$date, themeId=$themeId" }
|
||||||
|
|
||||||
val times: List<TimeWithAvailability> = timeFinder.findAllWithAvailabilityByDateAndThemeId(date, themeId)
|
val times: List<TimeWithAvailabilityResponse> =
|
||||||
|
timeFinder.findAllWithAvailabilityByDateAndThemeId(date, themeId)
|
||||||
|
.map {
|
||||||
|
TimeWithAvailabilityResponse(
|
||||||
|
id = it.timeId,
|
||||||
|
startAt = it.startAt,
|
||||||
|
isAvailable = it.isReservable
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return TimeWithAvailabilityListResponse(times.map { it.toResponse() })
|
return TimeWithAvailabilityListResponse(times)
|
||||||
.also { log.info { "[TimeService.findTimesWithAvailability] ${it.times.size}개 반환: date=$date, themeId=$themeId" } }
|
.also { log.info { "[TimeService.findTimesWithAvailability] ${it.times.size}개 반환: date=$date, themeId=$themeId" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,7 @@ class TimeServiceTest : FunSpec({
|
|||||||
|
|
||||||
assertSoftly(response.times) {
|
assertSoftly(response.times) {
|
||||||
it shouldHaveSize times.size
|
it shouldHaveSize times.size
|
||||||
it.map { time -> time.isAvailable } shouldContainExactly times.map { time -> time.canReserve() }
|
it.map { time -> time.isAvailable } shouldContainExactly times.map { time -> time.isReservable }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class TimeServiceTest : FunSpec({
|
|||||||
context("createTime") {
|
context("createTime") {
|
||||||
val request = TimeCreateRequest(startAt = LocalTime.of(10, 0))
|
val request = TimeCreateRequest(startAt = LocalTime.of(10, 0))
|
||||||
|
|
||||||
test("정상 저장") {
|
test("정상 응답") {
|
||||||
val time: TimeEntity = TimeFixture.create(startAt = request.startAt)
|
val time: TimeEntity = TimeFixture.create(startAt = request.startAt)
|
||||||
|
|
||||||
every {
|
every {
|
||||||
@ -139,7 +139,7 @@ class TimeServiceTest : FunSpec({
|
|||||||
}
|
}
|
||||||
|
|
||||||
context("deleteTime") {
|
context("deleteTime") {
|
||||||
test("정상 제거 및 응답") {
|
test("정상 응답") {
|
||||||
val id = 1L
|
val id = 1L
|
||||||
val time = TimeFixture.create(id = id)
|
val time = TimeFixture.create(id = id)
|
||||||
|
|
||||||
|
|||||||
@ -102,7 +102,7 @@ class TimeFinderTest : FunSpec({
|
|||||||
|
|
||||||
assertSoftly(result) {
|
assertSoftly(result) {
|
||||||
it shouldHaveSize 2
|
it shouldHaveSize 2
|
||||||
it.all { time -> time.canReserve() }
|
it.all { time -> time.isReservable }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user