generated from pricelees/issue-pr-template
30 lines
814 B
Kotlin
30 lines
814 B
Kotlin
package roomescape.common.config
|
|
|
|
import org.slf4j.MDC
|
|
import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.data.domain.AuditorAware
|
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing
|
|
import roomescape.auth.web.support.MDC_MEMBER_ID_KEY
|
|
import java.util.*
|
|
|
|
@Configuration
|
|
@EnableJpaAuditing
|
|
class JpaConfig {
|
|
|
|
@Bean
|
|
fun auditorAware(): AuditorAware<Long> = MdcAuditorAware()
|
|
}
|
|
|
|
class MdcAuditorAware : AuditorAware<Long> {
|
|
override fun getCurrentAuditor(): Optional<Long> {
|
|
val memberIdStr: String? = MDC.get(MDC_MEMBER_ID_KEY)
|
|
|
|
if (memberIdStr == null) {
|
|
return Optional.empty()
|
|
} else {
|
|
return Optional.of(memberIdStr.toLong())
|
|
}
|
|
}
|
|
}
|