diff --git a/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt b/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt index 0b86180..85f6ec8 100644 --- a/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt +++ b/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt @@ -2,6 +2,7 @@ package org.gitanimals.render.domain import jakarta.persistence.Column import jakarta.persistence.MappedSuperclass +import jakarta.persistence.PrePersist import org.springframework.data.annotation.CreatedDate import org.springframework.data.annotation.LastModifiedDate import java.time.Instant @@ -14,5 +15,14 @@ abstract class AbstractTime( @LastModifiedDate @Column(name = "modified_at") - val modifiedAt: Instant = createdAt, -) + var modifiedAt: Instant? = null, +) { + + @PrePersist + fun prePersist() { + modifiedAt = when (modifiedAt == null) { + true -> createdAt + false -> return + } + } +}