generated from pricelees/issue-pr-template
[#37] 테마 스키마 재정의 #38
25
src/main/kotlin/roomescape/common/config/JpaConfig.kt
Normal file
25
src/main/kotlin/roomescape/common/config/JpaConfig.kt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
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 = MDC.get(MDC_MEMBER_ID_KEY)
|
||||||
|
|
||||||
|
return Optional.ofNullable(memberIdStr.toLongOrNull())
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/main/kotlin/roomescape/common/entity/BaseEntityV2.kt
Normal file
55
src/main/kotlin/roomescape/common/entity/BaseEntityV2.kt
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package roomescape.common.entity
|
||||||
|
|
||||||
|
import jakarta.persistence.Column
|
||||||
|
import jakarta.persistence.EntityListeners
|
||||||
|
import jakarta.persistence.Id
|
||||||
|
import jakarta.persistence.MappedSuperclass
|
||||||
|
import jakarta.persistence.PostLoad
|
||||||
|
import jakarta.persistence.PrePersist
|
||||||
|
import org.springframework.data.annotation.CreatedBy
|
||||||
|
import org.springframework.data.annotation.CreatedDate
|
||||||
|
import org.springframework.data.annotation.LastModifiedBy
|
||||||
|
import org.springframework.data.annotation.LastModifiedDate
|
||||||
|
import org.springframework.data.domain.Persistable
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
@EntityListeners(AuditingEntityListener::class)
|
||||||
|
abstract class AuditingBaseEntity(
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
private val _id: Long,
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private var isNewEntity: Boolean = true
|
||||||
|
) : Persistable<Long> {
|
||||||
|
@Column(updatable = false)
|
||||||
|
@CreatedDate
|
||||||
|
lateinit var createdAt: LocalDateTime
|
||||||
|
protected set
|
||||||
|
|
||||||
|
@Column(updatable = false)
|
||||||
|
@CreatedBy
|
||||||
|
var createdBy: Long = 0L
|
||||||
|
protected set
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@LastModifiedDate
|
||||||
|
lateinit var updatedAt: LocalDateTime
|
||||||
|
protected set
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@LastModifiedBy
|
||||||
|
var updatedBy: Long = 0L
|
||||||
|
protected set
|
||||||
|
|
||||||
|
@PostLoad
|
||||||
|
@PrePersist
|
||||||
|
fun markNotNew() {
|
||||||
|
isNewEntity = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getId(): Long = _id
|
||||||
|
override fun isNew(): Boolean = isNewEntity
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user