Skip to content

Commit

Permalink
Merge pull request #249 from GSM-MSG/248-update/monday-reservation
Browse files Browse the repository at this point in the history
# 248 월요일 7교시 예약 가능하도록 수정
  • Loading branch information
JuuuuHong authored Apr 3, 2024
2 parents 0b233f8 + 42c8c7f commit 2d32ce9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.msg.hiv2.domain.homebase.application.usecase
import team.msg.hiv2.domain.homebase.application.service.HomeBaseService
import team.msg.hiv2.domain.homebase.exception.AlreadyExistReservationException
import team.msg.hiv2.domain.homebase.exception.AlreadyReservedAtSamePeriodException
import team.msg.hiv2.domain.homebase.exception.NotReserveHomeBaseDayException
import team.msg.hiv2.domain.homebase.exception.TooManyUsersException
import team.msg.hiv2.domain.homebase.presentation.data.request.ReservationHomeBaseRequest
import team.msg.hiv2.domain.reservation.application.service.ReservationService
Expand All @@ -11,6 +12,7 @@ import team.msg.hiv2.domain.reservation.domain.Reservation
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.exception.UserNotFoundException
import team.msg.hiv2.global.annotation.usecase.UseCase
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.util.*

Expand All @@ -25,7 +27,11 @@ class ReserveHomeBaseUseCase(
fun execute(floor: Int, period: Int, homeBaseNumber: Int, request: ReservationHomeBaseRequest) {

reservationValidator.validateReservationTime(LocalDateTime.now(), period)
reservationValidator.validateReservationDay(LocalDateTime.now())

val dayOfWeek = reservationValidator.validateReservationDay(LocalDateTime.now())

if (dayOfWeek != DayOfWeek.MONDAY && period == 7)
throw NotReserveHomeBaseDayException()

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.msg.hiv2.domain.homebase.exception

import team.msg.hiv2.global.error.ErrorCode
import team.msg.hiv2.global.error.exception.HiException

class NotReserveHomeBaseDayException : HiException(ErrorCode.NOT_RESERVE_HOME_BASE_DAY_EXCEPTION)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package team.msg.hiv2.domain.homebase.exception
import team.msg.hiv2.global.error.ErrorCode
import team.msg.hiv2.global.error.exception.HiException

class NotReserveHomeBaseHourException: HiException(ErrorCode.NOT_RESERVE_HOME_BASE_EXCEPTION)
class NotReserveHomeBaseHourException: HiException(ErrorCode.NOT_RESERVE_HOME_BASE_HOUR_EXCEPTION)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package team.msg.hiv2.domain.reservation.application.validator

import java.time.DayOfWeek
import java.time.LocalDateTime

interface ReservationValidator {
fun validateReservationTime(currentTime: LocalDateTime, period: Int)
fun validateReservationDay(currentTime: LocalDateTime)
fun validateReservationDay(currentTime: LocalDateTime): DayOfWeek
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@ class ReservationValidatorImpl : ReservationValidator {
*/
if (hour < 8 || (hour == 8 && minute < 10) || hour > 20 || (hour == 20 && minute > 30))
throw NotReserveHomeBaseHourException()

when (period) {
8 -> if ((hour == 16 && minute > 40) || hour > 16) throw NotReserveHomeBaseHourException()
9 -> if ((hour == 17 && minute > 40) || hour > 17) throw NotReserveHomeBaseHourException()
10 -> if ((hour == 18 && minute > 30) || hour > 18) throw NotReserveHomeBaseHourException()
11 -> if ((hour == 19 && minute > 30) || hour > 19) throw NotReserveHomeBaseHourException()
}
}

override fun validateReservationDay(currentTime: LocalDateTime) {
override fun validateReservationDay(currentTime: LocalDateTime): DayOfWeek {
val dayOfWeek = currentTime.dayOfWeek

// 금요일, 토요일, 일요일은 예약 불가능
if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY)
throw NotReserveHomeBaseHourException()

return dayOfWeek
}

}
3 changes: 2 additions & 1 deletion src/main/kotlin/team/msg/hiv2/global/error/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ enum class ErrorCode(
ALREADY_EXIST_RESERVATION("이미 예약 되어진 자리입니다.", 403),
ALREADY_RESERVED_AT_SAME_PERIOD("이미 같은 교시에 예약된 홈베이스가 존재합니다.", 409),
TOO_MANY_USERS_EXCEPTION("인원 수가 홈베이스 최대 인원보다 많습니다.", 403),
NOT_RESERVE_HOME_BASE_EXCEPTION("홈베이스 예약 가능한 시간이 아닙니다.", 403),
NOT_RESERVE_HOME_BASE_HOUR_EXCEPTION("홈베이스 예약 가능한 시간이 아닙니다.", 403),
NOT_RESERVE_HOME_BASE_DAY_EXCEPTION("7교시 홈베이스 예약은 월요일만 가능합니다.", 403),

// homeBase
HOME_BASE_NOT_FOUND("홈베이스를 찾을 수 없습니다.", 404),
Expand Down
10 changes: 0 additions & 10 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,10 @@ spring:
hibernate:
default_batch_fetch_size: 1000

datasource:
url: jdbc:mysql://${DB_URL:localhost:3306}/${DB_NAME:hiv2}?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul&allowPublicKeyRetrieval=true
username: ${DB_USER:root}
password: ${DB_PASSWORD:Esperer123!}
driver-class-name: com.mysql.cj.jdbc.Driver

sql:
init:
mode: always

redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}

jwt:
accessSecret: ${ACCESS_SECRET:qwertyuiopasdfghjklzxcvbnm12345678901234567890}
refreshSecret: ${REFRESH_SECRET:poiuytrewqlkjhgfdsamnbvcxz12345678901234567890}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</encoder>
</appender>

<logger name="org.springframework" level="ALL">
<logger name="org.springframework" level="INFO">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.hibernate.orm.jdbc.bind" level="TRACE">
Expand All @@ -31,7 +31,7 @@
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</layout>
<logGroupName>hi</logGroupName>
<logStreamUuidPrefix>hi-log-</logStreamUuidPrefix>
<logStreamUuidPrefix>hi-log</logStreamUuidPrefix>
<logRegion>ap-northeast-2</logRegion>
<maxBatchLogEvents>50</maxBatchLogEvents>
<maxFlushTimeMillis>30000</maxFlushTimeMillis>
Expand Down

0 comments on commit 2d32ce9

Please sign in to comment.