Skip to content

Commit

Permalink
Merge pull request #402 from Team-Ampersand/feat/logginghttp
Browse files Browse the repository at this point in the history
update :: validate day of week selfstudy util
  • Loading branch information
esperar authored Aug 8, 2024
2 parents 82a3c3c + 6716729 commit 293f4d4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ValidDayOfWeekAndHourMassageUtil {
val dayOfWeek = currentTime.dayOfWeek
val hour = currentTime.hour
val minute = currentTime.minute

if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY)
throw NotMassageCancelDayException()
if (hour == 20 && minute >= 20)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.dotori.v2.domain.selfstudy.properties

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import org.springframework.boot.context.properties.ConstructorBinding

@Configuration
@ConstructorBinding
@ConfigurationProperties(prefix = "self-study")
class SelfStudyProperties {
var allowedStartTime: String = "20:00"
var allowedEndTime: String = "20:59"
class SelfStudyProperties(
allowedStartTime: String,
allowedEndTime: String
) {
val allowedStartTime = allowedStartTime
val allowedEndTime = allowedEndTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import com.dotori.v2.domain.selfstudy.exception.NotSelfStudyApplyDayException
import com.dotori.v2.domain.selfstudy.exception.NotSelfStudyApplyHourException
import com.dotori.v2.domain.selfstudy.exception.NotSelfStudyCancelDayException
import com.dotori.v2.domain.selfstudy.exception.NotSelfStudyCancelHourException
import com.dotori.v2.global.error.ErrorCode
import com.dotori.v2.global.error.exception.BasicException
import org.springframework.core.env.Environment
import org.springframework.stereotype.Component
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.time.LocalTime

@Component
class ValidDayOfWeekAndHourUtil(
Expand All @@ -22,42 +20,46 @@ class ValidDayOfWeekAndHourUtil(
fun validateApply() {
val currentTime = LocalDateTime.now()
val dayOfWeek = currentTime.dayOfWeek
val hour = currentTime.hour
val minute = currentTime.minute

if (!isDevProfile() && (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY)) {
throw NotSelfStudyApplyDayException()
}

val allowedStartTime = selfStudyProperties.allowedStartTime?.let { LocalTime.parse(it) }
?: throw BasicException(ErrorCode.UNKNOWN_ERROR)
val allowedEndTime = selfStudyProperties.allowedEndTime?.let { LocalTime.parse(it) }
?: throw BasicException(ErrorCode.UNKNOWN_ERROR)
val allowedStartTime = selfStudyProperties.allowedStartTime.split(":").map { it.toInt() }.toIntArray()
val allowedEndTime = selfStudyProperties.allowedEndTime.split(":").map { it.toInt() }.toIntArray()

if (currentTime.toLocalTime().isBefore(allowedStartTime) || currentTime.toLocalTime().isAfter(allowedEndTime)) {
throw NotSelfStudyApplyHourException()
}
// 시간은 start hour: start minute ~ end 사이이면서
if (hour >= allowedStartTime[0] && minute >= allowedStartTime[1] && hour <= allowedEndTime[0] && minute <= allowedEndTime[1])
return

throw NotSelfStudyApplyHourException()
}

fun validateCancel() {
val currentTime = LocalDateTime.now()
val dayOfWeek = currentTime.dayOfWeek
val hour = currentTime.hour
val minute = currentTime.minute

if (!isDevProfile() && (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY)) {
throw NotSelfStudyCancelDayException()
}

val allowedStartTime = selfStudyProperties.allowedStartTime?.let { LocalTime.parse(it) }
?: throw BasicException(ErrorCode.UNKNOWN_ERROR)
val allowedEndTime = selfStudyProperties.allowedEndTime?.let { LocalTime.parse(it) }
?: throw BasicException(ErrorCode.UNKNOWN_ERROR)
val allowedStartTime = selfStudyProperties.allowedStartTime.split(":").map { it.toInt() }.toIntArray()
val allowedEndTime = selfStudyProperties.allowedEndTime.split(":").map { it.toInt() }.toIntArray()

if (currentTime.toLocalTime().isBefore(allowedStartTime) || currentTime.toLocalTime().isAfter(allowedEndTime)) {
throw NotSelfStudyCancelHourException()
}
if (hour >= allowedStartTime[0] && minute >= allowedStartTime[1] && hour <= allowedEndTime[0] && minute <= allowedEndTime[1])
return

throw NotSelfStudyCancelHourException()
}

private fun isDevProfile(): Boolean {
return environment.activeProfiles.contains("dev")
}

fun isApplyValid(): Boolean {
return try {
validateApply()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotori.v2.global.config

import com.dotori.v2.domain.selfstudy.properties.SelfStudyProperties
import com.dotori.v2.global.config.gauth.properties.GAuthProperties
import com.dotori.v2.global.security.jwt.properties.JwtProperties
import com.dotori.v2.global.security.jwt.properties.JwtTimeProperties
Expand All @@ -11,7 +12,8 @@ import org.springframework.context.annotation.Configuration
basePackageClasses = [
GAuthProperties::class,
JwtProperties::class,
JwtTimeProperties::class
JwtTimeProperties::class,
SelfStudyProperties::class
]
)
class ConfigurationPropertiesScanConfig
74 changes: 0 additions & 74 deletions src/main/resources/logback-spring.xml

This file was deleted.

0 comments on commit 293f4d4

Please sign in to comment.