Skip to content

Commit

Permalink
refactor: TimeBaseEntity가 TimeUtil을 사용하도록 수정하고 null-able을 없앤다
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed Mar 12, 2024
1 parent 35907de commit 842a1fa
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/kotlin/me/nalab/api/core/TimeBaseEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ abstract class TimeBaseEntity {
nullable = false,
updatable = false,
)
protected var createdAt: Instant? = null
protected lateinit var createdAt: Instant

@Column(name = "updated_at", columnDefinition = "TIMESTAMP(6)", nullable = false)
protected var updatedAt: Instant? = null
protected lateinit var updatedAt: Instant

@PrePersist
fun prePersist() {
val now = Instant.now()
createdAt = if (createdAt != null) createdAt else now
updatedAt = if (updatedAt != null) updatedAt else now
val now = TimeUtil.now()
createdAt = now
updatedAt = now
}

@PreUpdate
fun preUpdate() {
updatedAt = Instant.now()
updatedAt = TimeUtil.now()
}
}

0 comments on commit 842a1fa

Please sign in to comment.