diff --git a/compose.yaml b/compose.yaml index 8109905..ccb0ca3 100644 --- a/compose.yaml +++ b/compose.yaml @@ -10,8 +10,6 @@ services: POSTGRES_DB: eatda POSTGRES_USER: local POSTGRES_PASSWORD: local - TZ: Asia/Seoul - PGTZ: Asia/Seoul ports: - "15432:5432" restart: always diff --git a/src/main/kotlin/com/mjucow/eatda/common/config/JacksonConfiguration.kt b/src/main/kotlin/com/mjucow/eatda/common/config/JacksonConfiguration.kt new file mode 100644 index 0000000..97fd26d --- /dev/null +++ b/src/main/kotlin/com/mjucow/eatda/common/config/JacksonConfiguration.kt @@ -0,0 +1,18 @@ +package com.mjucow.eatda.common.config + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class JacksonConfiguration { + /** + * 기본 objectMapper 는 java8 이후 시간관련 타입(Instant 등)을 변환하지 못하므로 JavaTimeModule 추가 등록 + */ + @Bean + fun objectMapper(): ObjectMapper { + return jacksonObjectMapper().registerModule(JavaTimeModule()) + } +} diff --git a/src/main/kotlin/com/mjucow/eatda/domain/common/BaseEntity.kt b/src/main/kotlin/com/mjucow/eatda/domain/common/BaseEntity.kt index e15e267..f05f135 100644 --- a/src/main/kotlin/com/mjucow/eatda/domain/common/BaseEntity.kt +++ b/src/main/kotlin/com/mjucow/eatda/domain/common/BaseEntity.kt @@ -9,8 +9,7 @@ import jakarta.persistence.MappedSuperclass import jakarta.persistence.PrePersist import jakarta.persistence.PreUpdate import org.springframework.data.jpa.domain.support.AuditingEntityListener -import java.time.LocalDateTime -import java.time.ZoneId +import java.time.Instant @MappedSuperclass @EntityListeners(AuditingEntityListener::class) @@ -20,30 +19,30 @@ abstract class BaseEntity( val id: Long = DEFAULT_ID, ) { @Column(nullable = false, updatable = false) - var createdAt: LocalDateTime = LocalDateTime.now(ZONE_ID) + var createdAt: Instant = Instant.now() protected set @Column(nullable = false) - var updatedAt: LocalDateTime = LocalDateTime.now(ZONE_ID) + var updatedAt: Instant = Instant.now() protected set @PrePersist fun initTimeColumns() { - createdAt = LocalDateTime.now(ZONE_ID) - updatedAt = LocalDateTime.now(ZONE_ID) + createdAt = Instant.now() + updatedAt = Instant.now() } @PreUpdate fun updateTimeColumn() { - updatedAt = LocalDateTime.now(ZONE_ID) + updatedAt = Instant.now() } override fun equals(other: Any?): Boolean { + if (id == DEFAULT_ID) return false if (this === other) return true if (javaClass != other?.javaClass) return false other as BaseEntity - if (id == DEFAULT_ID || other.id == DEFAULT_ID) return false return id == other.id } @@ -54,6 +53,5 @@ abstract class BaseEntity( companion object { const val DEFAULT_ID = 0L - val ZONE_ID: ZoneId = ZoneId.of("Asia/Seoul") } }