Skip to content

Commit

Permalink
feat: BaseEntity 적용 (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
khabh authored Oct 8, 2024
1 parent 2bd9140 commit 6507709
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/server/haengdong/config/JpaConfig.java
Original file line number Diff line number Diff line change
@@ -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 {
}
23 changes: 23 additions & 0 deletions server/src/main/java/server/haengdong/domain/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 2 additions & 1 deletion server/src/main/java/server/haengdong/domain/bill/Bill.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 6507709

Please sign in to comment.