Skip to content

Commit

Permalink
fix: Article merge 시 createdAt null이 되는 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
jihwan2da committed Jan 21, 2024
1 parent 36ece50 commit 60005c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions community-domain/src/main/kotlin/gloddy/article/Article.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import gloddy.article.vo.ArticleImage
import gloddy.category.Category
import gloddy.core.ArticleId
import gloddy.core.UserId
import java.time.LocalDateTime
import java.time.LocalDateTime.*

data class Article(
val userId: UserId,
Expand All @@ -14,6 +16,7 @@ data class Article(
val image: ArticleImage,
val commentCount: Int = 0,
val likeCount: Int = 0,
val createdAt: LocalDateTime = now(),
val id: ArticleId? = null,
) {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import gloddy.persistence.common.BaseTimeEntity
import gloddy.persistence.util.converter.StringArrayConverter
import jakarta.persistence.*
import org.hibernate.annotations.SQLRestriction
import java.time.LocalDateTime

@Entity
@Table(name = "article")
Expand Down Expand Up @@ -35,7 +36,11 @@ class ArticleJpaEntity(
@field:Id
@field:GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
) : BaseTimeEntity() {

createdAt: LocalDateTime? = null
) : BaseTimeEntity(
createdAt = createdAt
) {
fun changeDeletedToTrue() {
this.deleted = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import gloddy.core.ArticleId
import gloddy.core.UserId
import gloddy.persistence.article.ArticleJpaEntity
import gloddy.persistence.article.ArticleLikeJpaEntity
import kotlin.io.path.createTempDirectory

fun Article.toEntity() : ArticleJpaEntity =
ArticleJpaEntity(
Expand All @@ -17,6 +18,7 @@ fun Article.toEntity() : ArticleJpaEntity =
images = this.image.images,
commentCount = this.commentCount,
likeCount = this.likeCount,
createdAt = this.createdAt,
id = this.id?.value
)

Expand All @@ -29,6 +31,7 @@ fun ArticleJpaEntity.toDomain() : Article =
image = ArticleImage(this.images),
commentCount = this.commentCount,
likeCount = this.likeCount,
createdAt = this.createdAt!!,
id = ArticleId(this.id!!)
)

Expand Down

0 comments on commit 60005c2

Please sign in to comment.