diff --git a/server/src/main/java/server/haengdong/HaengdongApplication.java b/server/src/main/java/server/haengdong/HaengdongApplication.java index 4a84c6120..f25499e01 100644 --- a/server/src/main/java/server/haengdong/HaengdongApplication.java +++ b/server/src/main/java/server/haengdong/HaengdongApplication.java @@ -3,6 +3,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @Slf4j @SpringBootApplication diff --git a/server/src/main/java/server/haengdong/config/JpaConfig.java b/server/src/main/java/server/haengdong/config/JpaConfig.java new file mode 100644 index 000000000..f0210e4b0 --- /dev/null +++ b/server/src/main/java/server/haengdong/config/JpaConfig.java @@ -0,0 +1,9 @@ +package server.haengdong.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class JpaConfig { +} diff --git a/server/src/main/java/server/haengdong/domain/BaseEntity.java b/server/src/main/java/server/haengdong/domain/BaseEntity.java new file mode 100644 index 000000000..2eb4aa01c --- /dev/null +++ b/server/src/main/java/server/haengdong/domain/BaseEntity.java @@ -0,0 +1,23 @@ +package server.haengdong.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import java.time.Instant; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@EntityListeners(AuditingEntityListener.class) +@MappedSuperclass +public abstract class BaseEntity { + + @Column(updatable = false) + @CreatedDate + private Instant createdAt; + + @LastModifiedDate + private Instant updatedAt; +} diff --git a/server/src/main/java/server/haengdong/domain/bill/Bill.java b/server/src/main/java/server/haengdong/domain/bill/Bill.java index 6face8274..747a526e0 100644 --- a/server/src/main/java/server/haengdong/domain/bill/Bill.java +++ b/server/src/main/java/server/haengdong/domain/bill/Bill.java @@ -19,6 +19,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.domain.BaseEntity; import server.haengdong.domain.member.Member; import server.haengdong.domain.event.Event; import server.haengdong.exception.HaengdongErrorCode; @@ -27,7 +28,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -public class Bill { +public class Bill extends BaseEntity { private static final int MIN_TITLE_LENGTH = 1; private static final int MAX_TITLE_LENGTH = 30; diff --git a/server/src/main/java/server/haengdong/domain/bill/BillDetail.java b/server/src/main/java/server/haengdong/domain/bill/BillDetail.java index 6f3bcf973..8a754b2b9 100644 --- a/server/src/main/java/server/haengdong/domain/bill/BillDetail.java +++ b/server/src/main/java/server/haengdong/domain/bill/BillDetail.java @@ -11,12 +11,13 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.domain.BaseEntity; import server.haengdong.domain.member.Member; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -public class BillDetail { +public class BillDetail extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/server/src/main/java/server/haengdong/domain/event/Event.java b/server/src/main/java/server/haengdong/domain/event/Event.java index 58d080a43..a7cc00fb3 100644 --- a/server/src/main/java/server/haengdong/domain/event/Event.java +++ b/server/src/main/java/server/haengdong/domain/event/Event.java @@ -7,17 +7,19 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import java.time.Instant; import java.util.Arrays; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.domain.BaseEntity; import server.haengdong.exception.HaengdongErrorCode; import server.haengdong.exception.HaengdongException; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -public class Event { +public class Event extends BaseEntity { private static final int MIN_NAME_LENGTH = 1; private static final int MAX_NAME_LENGTH = 20; diff --git a/server/src/main/java/server/haengdong/domain/event/EventImage.java b/server/src/main/java/server/haengdong/domain/event/EventImage.java index cc5aad0dd..11419abc8 100644 --- a/server/src/main/java/server/haengdong/domain/event/EventImage.java +++ b/server/src/main/java/server/haengdong/domain/event/EventImage.java @@ -11,11 +11,12 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.domain.BaseEntity; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -public class EventImage { +public class EventImage extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/server/src/main/java/server/haengdong/domain/member/Member.java b/server/src/main/java/server/haengdong/domain/member/Member.java index 25a19ccb0..2c9cb41d6 100644 --- a/server/src/main/java/server/haengdong/domain/member/Member.java +++ b/server/src/main/java/server/haengdong/domain/member/Member.java @@ -14,6 +14,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.domain.BaseEntity; import server.haengdong.domain.event.Event; import server.haengdong.exception.HaengdongErrorCode; import server.haengdong.exception.HaengdongException; @@ -22,7 +23,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"event_id", "name"})}) @Entity -public class Member { +public class Member extends BaseEntity { private static final int MIN_NAME_LENGTH = 1; private static final int MAX_NAME_LENGTH = 8;