Skip to content

Commit

Permalink
Merge pull request #210 from GSM-MSG/209-add/homebase-entity-field
Browse files Browse the repository at this point in the history
# 209 홈베이스 엔티티 프로퍼티 변경
  • Loading branch information
JuuuuHong authored Mar 19, 2024
2 parents 7c0e99e + 8d41bef commit f63b138
Show file tree
Hide file tree
Showing 52 changed files with 204 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface HomeBaseFacade {

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

override fun reserveHomeBase(floor: Int, period: Int, request: ReservationHomeBaseRequest) =
reserveHomeBaseUseCase.execute(floor, period, request)
override fun reserveHomeBase(floor: Int, period: Int, homeBaseNumber: Int, request: ReservationHomeBaseRequest) =
reserveHomeBaseUseCase.execute(floor, period, homeBaseNumber, request)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import team.msg.hiv2.domain.homebase.domain.HomeBase

interface QueryHomeBaseService {

fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): HomeBase
fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): List<HomeBase>
fun queryHomeBaseByFloorAndPeriodAndHomeBaseNumber(floor: Int, period: Int, homeBaseNumber: Int): HomeBase
fun queryAllHomeBaseByPeriod(period: Int): List<HomeBase>
fun queryHomeBaseById(id: Long): HomeBase
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import team.msg.hiv2.global.annotation.service.DomainService
class QueryHomeBaseServiceImpl(
private val queryHomeBasePort: QueryHomeBasePort
) : QueryHomeBaseService {
override fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): List<HomeBase> =
queryHomeBasePort.queryHomeBaseByFloorAndPeriod(floor, period)

override fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): HomeBase =
queryHomeBasePort.queryHomeBaseByFloorAndPeriod(floor, period) ?: throw HomeBaseNotFoundException()
override fun queryHomeBaseByFloorAndPeriodAndHomeBaseNumber(floor: Int, period: Int, homeBaseNumber: Int): HomeBase =
queryHomeBasePort.queryHomeBaseByFloorAndPeriodAndHomeBaseNumber(floor, period, homeBaseNumber) ?: throw HomeBaseNotFoundException()

override fun queryAllHomeBaseByPeriod(period: Int): List<HomeBase> =
queryHomeBasePort.queryAllHomeBaseByPeriod(period)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import team.msg.hiv2.domain.homebase.domain.HomeBase

interface QueryHomeBasePort {

fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): HomeBase?
fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): List<HomeBase>
fun queryHomeBaseByFloorAndPeriodAndHomeBaseNumber(floor: Int, period: Int, homeBaseNumber: Int): HomeBase?
fun queryAllHomeBaseByPeriod(period: Int): List<HomeBase>
fun queryHomeBaseById(id: Long): HomeBase?
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.presentation.data.response.HomeBaseResponse
import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationResponse
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.user.application.service.UserService
Expand All @@ -19,17 +19,18 @@ class QueryReservationByHomeBaseUseCase(

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

val homeBase = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)
val homeBases = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)

val reservations = reservationService.queryAllReservationByHomeBase(homeBase)
val reservations = reservationService.queryAllReservationByHomeBaseIn(homeBases)

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(homeBase.id, floor, period)
HomeBaseResponse.of(homeBase)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ReserveHomeBaseUseCase(
private val teamService: TeamService
) {

fun execute(floor: Int, period: Int, request: ReservationHomeBaseRequest) {
fun execute(floor: Int, period: Int, homeBaseNumber: Int, request: ReservationHomeBaseRequest) {

val homeBase = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)
val homeBase = homeBaseService.queryHomeBaseByFloorAndPeriodAndHomeBaseNumber(floor, period, homeBaseNumber)

val users = userService.queryAllUserById(request.users)

Expand All @@ -37,7 +37,7 @@ class ReserveHomeBaseUseCase(
4 -> if(reservationCount > 5) throw ForbiddenReserveException()
}

if(reservationService.existsByHomeBaseAndReservationNumber(homeBase, request.reservationNumber))
if(reservationService.existsByHomeBase(homeBase))
throw AlreadyExistReservationException()

val team = teamService.save(
Expand All @@ -53,8 +53,7 @@ class ReserveHomeBaseUseCase(
reason = request.reason,
homeBaseId = homeBase.id,
teamId = team.id,
checkStatus = false,
reservationNumber = request.reservationNumber
checkStatus = false
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import team.msg.hiv2.global.annotation.Aggregate
data class HomeBase(
val id: Long,
val floor: Int,
val period: Int
val period: Int,
val homeBaseNumber: Int,
val maxCapacity: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class HomeBasePersistenceAdapter(
private val homeBaseRepository: HomeBaseRepository,
private val homeBaseMapper: HomeBaseMapper
) : HomeBasePort {
override fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): List<HomeBase> =
homeBaseRepository.findByFloorAndPeriod(floor, period).map { homeBaseMapper.toDomain(it)!! }

override fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): HomeBase? =
homeBaseMapper.toDomain(homeBaseRepository.findByFloorAndPeriod(floor, period))
override fun queryHomeBaseByFloorAndPeriodAndHomeBaseNumber(floor: Int, period: Int, homeBaseNumber: Int): HomeBase? =
homeBaseMapper.toDomain(homeBaseRepository.findByFloorAndPeriodAndHomeBaseNumber(floor, period, homeBaseNumber))

override fun queryAllHomeBaseByPeriod(period: Int): List<HomeBase> =
homeBaseRepository.findAllByPeriod(period).map { homeBaseMapper.toDomain(it)!! }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team.msg.hiv2.domain.homebase.persistence.entity

import javax.persistence.Column
import team.msg.hiv2.global.entity.BaseIdEntity
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.Table

Expand All @@ -15,6 +15,12 @@ class HomeBaseJpaEntity(
val floor: Int,

@Column(name = "period", nullable = false)
val period: Int
val period: Int,

@Column(name = "home_base_number", nullable = false)
val homeBaseNumber: Int,

@Column(name = "max_capacity", nullable = false)
val maxCapacity: Int

) : BaseIdEntity(id)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class HomeBaseMapper : GenericMapper<HomeBase, HomeBaseJpaEntity> {
HomeBase(
id = it.id,
floor = it.floor,
period = it.period
period = it.period,
homeBaseNumber = it.homeBaseNumber,
maxCapacity = it.maxCapacity
)
}

Expand All @@ -22,7 +24,9 @@ class HomeBaseMapper : GenericMapper<HomeBase, HomeBaseJpaEntity> {
HomeBaseJpaEntity(
id = it.id,
floor = it.floor,
period = it.period
period = it.period,
homeBaseNumber = it.homeBaseNumber,
maxCapacity = it.maxCapacity
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import team.msg.hiv2.domain.homebase.persistence.entity.HomeBaseJpaEntity

interface HomeBaseRepository : CrudRepository<HomeBaseJpaEntity, Long> {

fun findByFloorAndPeriod(floor: Int, period: Int): HomeBaseJpaEntity?
fun findByFloorAndPeriod(floor: Int, period: Int): List<HomeBaseJpaEntity>
fun findByFloorAndPeriodAndHomeBaseNumber(floor: Int, period: Int, homeBaseNumber: Int): HomeBaseJpaEntity?
fun findAllByPeriod(period: Int): List<HomeBaseJpaEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class HomeBaseWebAdapter(
@PostMapping
fun reserveHomeBase(@RequestParam floor: Int,
@RequestParam period: Int,
@RequestParam homeBaseNumber: Int,
@Valid @RequestBody request: ReservationHomeBaseWebRequest): ResponseEntity<Void> =
homeBaseFacade.reserveHomeBase(floor, period, ReservationHomeBaseRequest(request.users, request.reason, request.reservationNumber))
homeBaseFacade.reserveHomeBase(floor, period, homeBaseNumber, ReservationHomeBaseRequest(request.users, request.reason))
.let { ResponseEntity.status(HttpStatus.CREATED).build() }

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import java.util.UUID

data class ReservationHomeBaseRequest(
val users: MutableList<UUID>,
val reason: String,
val reservationNumber: Int
val reason: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package team.msg.hiv2.domain.homebase.presentation.data.response

import team.msg.hiv2.domain.homebase.domain.HomeBase

data class HomeBaseResponse(
val homeBaseId: Long,
val floor: Int,
val period: Int,
val homeBaseNumber: Int,
val maxCapacity: Int
) {
companion object {
fun of(homeBase: HomeBase) = HomeBaseResponse(
homeBaseId = homeBase.id,
floor = homeBase.floor,
period = homeBase.period,
homeBaseNumber = homeBase.homeBaseNumber,
maxCapacity = homeBase.maxCapacity
)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package team.msg.hiv2.domain.homebase.presentation.data.web

import javax.validation.constraints.Max
import javax.validation.constraints.Min
import java.util.*
import javax.validation.constraints.NotBlank
import javax.validation.constraints.Size
import java.util.*

data class ReservationHomeBaseWebRequest(
@field:Size(min = 2, max = 6)
val users: MutableList<UUID>,
@field:NotBlank
val reason: String,
@field:Min(1, message = "Value must be between 1 and 6")
@field:Max(6, message = "Value must be between 1 and 6")
val reservationNumber: Int
val reason: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package team.msg.hiv2.domain.notice.persistence.entity

import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table
Expand All @@ -20,7 +21,7 @@ class NoticeJpaEntity(
@Column(nullable = false)
val content: String,

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val user: UserJpaEntity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.UUID

interface ReservationFacade {

fun checkAndRestrictReservation(id: UUID)
fun checkAndRestrictReservation()
fun deleteAllReservation()
fun deleteReservation(id: UUID)
fun exitReservation(id: UUID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ReservationFacadeImpl(
private val updateReservationUseCase: UpdateReservationUseCase
) : ReservationFacade {

override fun checkAndRestrictReservation(id: UUID) =
checkAndRestrictReservationUserUseCase.execute(id)
override fun checkAndRestrictReservation() =
checkAndRestrictReservationUserUseCase.execute()

override fun deleteAllReservation() =
deleteAllReservationUseCase.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,17 @@ package team.msg.hiv2.domain.reservation.application.scheduler

import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.domain.constant.UseStatus
import team.msg.hiv2.domain.reservation.application.usecase.CheckAndRestrictReservationUserUseCase

@Component
class ReservationScheduler(
private val reservationService: ReservationService,
private val userService: UserService,
private val teamService: TeamService
private val checkAndRestrictReservationUserUseCase: CheckAndRestrictReservationUserUseCase
) {

/**
* 매일 08시 30분에 전체 예약 테이블 삭제와 유저 정지 여부 검증
*/
@Scheduled(cron = "0 30 8 ? * MON-FRI", zone = "Asia/Seoul")
fun resetAllReservation() = checkAndDelete()
@Scheduled(cron = "0 8 18 ? * MON-FRI", zone = "Asia/Seoul")
fun resetAllReservation() = checkAndRestrictReservationUserUseCase.execute()

private fun checkAndDelete() {

val reservations = reservationService.queryAllReservation()

val teams = teamService.queryAllTeam()

val userIds = teams.flatMap { it.userIds }

val users = userService.queryAllUserById(userIds)

val updatedUsers = users.flatMap {
reservations.map { reservation ->
when (reservation.checkStatus) {
true -> it.copy(useStatus = UseStatus.AVAILABLE)
false -> it.copy(useStatus = UseStatus.UNAVAILABLE)
}
}
}

teamService.deleteAllInBatch(teams)
userService.saveAll(updatedUsers)
reservationService.deleteAllReservationInBatch(reservations)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ interface CommandReservationService{

fun save(reservation: Reservation): Reservation
fun delete(reservation: Reservation)
fun deleteAll()
fun deleteAllInBatch()
fun deleteAllReservationInBatch(reservations: List<Reservation>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CommandReservationServiceImpl(
commandReservationPort.delete(reservation)
}

override fun deleteAll() {
override fun deleteAllInBatch() {
commandReservationPort.deleteAllInBatch()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ interface QueryReservationService {
fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation>
fun queryAllReservation(): List<Reservation>
fun countReservationByHomeBase(homeBase: HomeBase): Int
fun existsByHomeBaseAndReservationNumber(homeBase: HomeBase, reservationNumber: Int): Boolean
fun existsByHomeBase(homeBase: HomeBase): Boolean
fun queryAllReservationByTeams(teams: List<Team>): List<Reservation>
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class QueryReservationServiceImpl(
override fun countReservationByHomeBase(homeBase: HomeBase): Int =
queryReservationPort.countReservationByHomeBase(homeBase)

override fun existsByHomeBaseAndReservationNumber(homeBase: HomeBase,reservationNumber: Int): Boolean =
queryReservationPort.existsByHomeBaseAndReservationNumber(homeBase, reservationNumber)
override fun existsByHomeBase(homeBase: HomeBase): Boolean =
queryReservationPort.existsByHomeBase(homeBase)

override fun queryAllReservationByTeams(teams: List<Team>): List<Reservation> =
queryReservationPort.queryAllReservationByTeams(teams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ interface QueryReservationPort {
fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation>
fun queryAllReservations(): List<Reservation>
fun countReservationByHomeBase(homeBase: HomeBase): Int
fun existsByHomeBaseAndReservationNumber(homeBase: HomeBase, reservationNumber: Int): Boolean
fun existsByHomeBase(homeBase: HomeBase): Boolean
fun queryAllReservationByTeams(teams: List<Team>): List<Reservation>
}
Loading

0 comments on commit f63b138

Please sign in to comment.