Skip to content

Commit

Permalink
refactor(damaba): #54 PromotionImage에 soft delete 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Wo-ogie committed Nov 11, 2024
1 parent aa877cb commit 925252f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import java.time.LocalDateTime

@Table(name = "promotion_image")
@Entity
Expand All @@ -37,6 +38,10 @@ class PromotionImageJpaEntity(
var url: String = url
private set

@Column(name = "deleted_at", nullable = true)
var deletedAt: LocalDateTime? = null
private set

fun toDomain(): PromotionImage = PromotionImage(
name = this.name,
url = this.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ class PromotionJpaEntity(
var deletedAt: LocalDateTime? = null
private set

@OneToMany(mappedBy = "promotion", cascade = [CascadeType.ALL], orphanRemoval = true)
var images: MutableList<PromotionImageJpaEntity> = mutableListOf()
private set
@OneToMany(mappedBy = "promotion", cascade = [CascadeType.PERSIST])
private var _images: MutableList<PromotionImageJpaEntity> = mutableListOf()

val images: List<PromotionImageJpaEntity>
get() = _images.filter { image -> image.deletedAt == null }.toList()

@OneToMany(mappedBy = "promotion", cascade = [CascadeType.ALL], orphanRemoval = true)
var activeRegions: MutableSet<PromotionActiveRegionJpaEntity> = mutableSetOf()
Expand Down Expand Up @@ -138,7 +140,7 @@ class PromotionJpaEntity(
val promotionImageJpaEntities = promotion.images.map { promotionImage ->
PromotionImageJpaEntity.from(promotionImage, promotionJpaEntity)
}
promotionJpaEntity.images.addAll(promotionImageJpaEntities)
promotionJpaEntity._images.addAll(promotionImageJpaEntities)

val promotionActiveRegionJpaEntities = promotion.activeRegions.map { promotionActiveRegion ->
PromotionActiveRegionJpaEntity.from(promotionActiveRegion, promotionJpaEntity)
Expand Down
1 change: 1 addition & 0 deletions damaba/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ CREATE TABLE promotion_image
url VARCHAR(255) NOT NULL UNIQUE,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
deleted_at DATETIME,
created_by BIGINT NOT NULL,
updated_by BIGINT NOT NULL,
PRIMARY KEY (id)
Expand Down

0 comments on commit 925252f

Please sign in to comment.