From d7f0838ab21f723609ecd04a68f86b606d6498f3 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Wed, 8 May 2024 21:44:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20TrafficEntity=EC=9D=98=20SoftDeleteList?= =?UTF-8?q?ener=20=EA=B5=AC=ED=98=84,=20=EC=A0=81=EC=9A=A9=ED=95=A9?= =?UTF-8?q?=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/TrafficEntitySoftDeleteListener.java | 12 ++++++++++++ .../walking/data/entity/traffic/TrafficEntity.java | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java diff --git a/data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java b/data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java new file mode 100644 index 00000000..d9539fd3 --- /dev/null +++ b/data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java @@ -0,0 +1,12 @@ +package com.walking.data.entity.support.listener; + +import com.walking.data.entity.traffic.TrafficEntity; +import javax.persistence.PreRemove; + +public class TrafficEntitySoftDeleteListener { + + @PreRemove + private void preRemove(TrafficEntity entity) { + entity.delete(); + } +} diff --git a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java index d2788657..e6eef41a 100644 --- a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java +++ b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java @@ -1,8 +1,10 @@ package com.walking.data.entity.traffic; +import com.walking.data.entity.support.listener.TrafficEntitySoftDeleteListener; import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -16,11 +18,13 @@ import org.locationtech.jts.geom.Point; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Entity +@EntityListeners({AuditingEntityListener.class, TrafficEntitySoftDeleteListener.class}) @Builder(toBuilder = true) @Table(name = "traffic") @SQLDelete(sql = "UPDATE traffic SET deleted=true where id=?")