Skip to content

Commit

Permalink
Merge pull request #212 from GSM-MSG/211-add/response-empty-home-base
Browse files Browse the repository at this point in the history
# 211 비어있는 홈베이스 반환
  • Loading branch information
JuuuuHong authored Mar 19, 2024
2 parents f63b138 + 1bb40ef commit f6abcf3
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationRe
interface HomeBaseFacade {

fun deleteAllReservationByPeriod(period: Int)
fun queryReservationByHomeBase(floor: Int, period: Int): List<ReservationResponse>
fun queryReservationByHomeBase(floor: Int, period: Int): List<ReservationResponse?>
fun reserveHomeBase(floor: Int, period: Int, homeBaseNumber: Int, request: ReservationHomeBaseRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HomeBaseFacadeImpl(
override fun deleteAllReservationByPeriod(period: Int) =
deleteAllReservationByPeriodUseCase.execute(period)

override fun queryReservationByHomeBase(floor: Int, period: Int): List<ReservationResponse> =
override fun queryReservationByHomeBase(floor: Int, period: Int): List<ReservationResponse?> =
queryReservationByHomeBaseUseCase.execute(floor, period)

override fun reserveHomeBase(floor: Int, period: Int, homeBaseNumber: Int, request: ReservationHomeBaseRequest) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@ package team.msg.hiv2.domain.homebase.application.usecase

import team.msg.hiv2.domain.homebase.application.service.QueryHomeBaseService
import team.msg.hiv2.domain.homebase.presentation.data.response.HomeBaseResponse
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.reservation.application.spi.QueryReservationPort
import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationResponse
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.team.application.spi.TeamPort
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.presentation.data.response.UserResponse
import team.msg.hiv2.global.annotation.usecase.ReadOnlyUseCase

@ReadOnlyUseCase
class QueryReservationByHomeBaseUseCase(
private val reservationService: ReservationService,
private val homeBaseService: QueryHomeBaseService,
private val userService: UserService,
private val teamService: TeamService
private val reservationPort: QueryReservationPort,
private val teamPort: TeamPort
) {

fun execute(floor: Int, period: Int): List<ReservationResponse> {
fun execute(floor: Int, period: Int): List<ReservationResponse?> {

val homeBases = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)

val reservations = reservationService.queryAllReservationByHomeBaseIn(homeBases)
return homeBases.map {
reservationPort.queryReservationByHomeBase(it)?.let { reservation ->
teamPort.queryTeamById(reservation.teamId)?.let { team ->
val users = userService.queryAllUserById(team.userIds)

return reservations.map {
val team = teamService.queryTeamById(it.teamId)
val users = userService.queryAllUserById(team.userIds)
val homeBase = homeBaseService.queryHomeBaseById(it.homeBaseId)
ReservationResponse.of(
it,
users.map { user -> UserResponse.of(user) },
HomeBaseResponse.of(homeBase)
ReservationResponse.of(
reservation,
users.map(UserResponse::of),
HomeBaseResponse.of(it)
)
}
} ?: ReservationResponse.of(
null,
null,
HomeBaseResponse.of(it)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HomeBaseWebAdapter(
.let { ResponseEntity.status(HttpStatus.CREATED).build() }

@GetMapping
fun queryHomeBaseReservation(@RequestParam floor: Int, @RequestParam period: Int): ResponseEntity<List<ReservationResponse>> =
fun queryHomeBaseReservation(@RequestParam floor: Int, @RequestParam period: Int): ResponseEntity<List<ReservationResponse?>> =
homeBaseFacade.queryReservationByHomeBase(floor, period)
.let { ResponseEntity.ok(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.*
interface QueryReservationService {

fun queryReservationById(id: UUID): Reservation
fun queryAllReservationByHomeBase(homeBase: HomeBase): List<Reservation>
fun queryReservationByHomeBase(homeBase: HomeBase): Reservation?
fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation>
fun queryAllReservation(): List<Reservation>
fun countReservationByHomeBase(homeBase: HomeBase): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class QueryReservationServiceImpl(
override fun queryReservationById(id: UUID): Reservation =
queryReservationPort.queryReservationById(id) ?: throw ReservationNotFoundException()

override fun queryAllReservationByHomeBase(homeBase: HomeBase): List<Reservation> =
queryReservationPort.queryAllReservationByHomeBase(homeBase)
override fun queryReservationByHomeBase(homeBase: HomeBase): Reservation? =
queryReservationPort.queryReservationByHomeBase(homeBase)

override fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation> =
queryReservationPort.queryAllReservationByHomeBaseIn(homeBases)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.UUID
interface QueryReservationPort {

fun queryReservationById(id: UUID): Reservation?
fun queryAllReservationByHomeBase(homeBase: HomeBase): List<Reservation>
fun queryReservationByHomeBase(homeBase: HomeBase): Reservation?
fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation>
fun queryAllReservations(): List<Reservation>
fun countReservationByHomeBase(homeBase: HomeBase): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ class ReservationPersistenceAdapter(
override fun queryReservationById(id: UUID) =
reservationMapper.toDomain(reservationRepository.findByIdOrNull(id))

override fun queryAllReservationByHomeBase(homeBase: HomeBase): List<Reservation> =
reservationRepository.findAllByHomeBase(homeBaseMapper.toEntity(homeBase))
.map { reservationMapper.toDomain(it)!! }
override fun queryReservationByHomeBase(homeBase: HomeBase): Reservation? =
reservationMapper.toDomain(reservationRepository.findByHomeBase(homeBaseMapper.toEntity(homeBase)))

override fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation> =
reservationRepository.findAllByHomeBaseIn(homeBases.map { homeBaseMapper.toEntity(it) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.*
interface ReservationRepository : JpaRepository<ReservationJpaEntity, UUID> {

@EntityGraph(attributePaths = ["homeBase"])
fun findAllByHomeBase(homeBase: HomeBaseJpaEntity): List<ReservationJpaEntity>
fun findByHomeBase(homeBase: HomeBaseJpaEntity): ReservationJpaEntity?
@EntityGraph(attributePaths = ["homeBase"])
fun findAllByHomeBaseIn(homeBases: List<HomeBaseJpaEntity>): List<ReservationJpaEntity>
@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import team.msg.hiv2.domain.user.presentation.data.response.UserResponse
import java.util.*

data class ReservationResponse(
val reservationId: UUID,
val users: List<UserResponse>,
val checkStatus: Boolean,
val homeBase: HomeBaseResponse
val reservationId: UUID?,
val users: List<UserResponse>?,
val checkStatus: Boolean?,
val homeBase: HomeBaseResponse?
) {
companion object {
fun of(reservation: Reservation, users: List<UserResponse>, homeBase: HomeBaseResponse) = ReservationResponse(
reservationId = reservation.id,
fun of(reservation: Reservation?, users: List<UserResponse>?, homeBase: HomeBaseResponse?) = ReservationResponse(
reservationId = reservation?.id,
users = users,
checkStatus = reservation.checkStatus,
checkStatus = reservation?.checkStatus,
homeBase = homeBase
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spring:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
hibernate:
ddl-auto: ${DDL_AUTO:update}
ddl-auto: ${DDL_AUTO:update}
properties:
hibernate:
default_batch_fetch_size: 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
import org.mockito.kotlin.given
import team.msg.hiv2.domain.homebase.application.service.HomeBaseService
import team.msg.hiv2.domain.homebase.application.service.QueryHomeBaseService
import team.msg.hiv2.domain.homebase.domain.HomeBase
import team.msg.hiv2.domain.homebase.presentation.data.response.HomeBaseResponse
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.reservation.application.spi.QueryReservationPort
import team.msg.hiv2.domain.reservation.domain.Reservation
import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationResponse
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.team.application.spi.TeamPort
import team.msg.hiv2.domain.team.domain.Team
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.domain.User
Expand All @@ -25,16 +25,16 @@ import java.util.*
class QueryReservationByHomeBaseUseCaseTest {

@Mock
private lateinit var reservationService: ReservationService
private lateinit var queryReservationPort: QueryReservationPort

@Mock
private lateinit var homeBaseService: HomeBaseService
private lateinit var queryHomeBaseService: QueryHomeBaseService

@Mock
private lateinit var userService: UserService

@Mock
private lateinit var teamService: TeamService
private lateinit var teamPort: TeamPort

private lateinit var queryReservationByHomeBaseUseCase: QueryReservationByHomeBaseUseCase

Expand Down Expand Up @@ -126,29 +126,26 @@ class QueryReservationByHomeBaseUseCaseTest {
@BeforeEach
fun setUp(){
queryReservationByHomeBaseUseCase = QueryReservationByHomeBaseUseCase(
reservationService, homeBaseService, userService, teamService
queryHomeBaseService, userService, queryReservationPort, teamPort
)
}

@Test
fun `예약 현황 조회 성공`(){

// given
given(homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period))
given(queryHomeBaseService.queryHomeBaseByFloorAndPeriod(floor, period))
.willReturn(listOf(homeBaseStub))

given(reservationService.queryAllReservationByHomeBaseIn(listOf(homeBaseStub)))
.willReturn(listOf(reservationStub))
given(queryReservationPort.queryReservationByHomeBase(homeBaseStub))
.willReturn(reservationStub)

given(teamService.queryTeamById(teamId))
given(teamPort.queryTeamById(teamId))
.willReturn(teamStub)

given(userService.queryAllUserById(listOf(userId1, userId2)))
.willReturn(listOf(userStub1, userStub2))

given(homeBaseService.queryHomeBaseById(reservationStub.homeBaseId))
.willReturn(homeBaseStub)

// when
val response = queryReservationByHomeBaseUseCase.execute(floor, period)

Expand Down

0 comments on commit f6abcf3

Please sign in to comment.