Skip to content

Commit

Permalink
feat: DB 데이터 생성 및 수정 시 시간을 기록하기 위한 BaseEntity 적용 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
devkimc authored Jun 11, 2023
1 parent 2c60b46 commit 7a2cf78
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 15 deletions.
24 changes: 24 additions & 0 deletions src/main/java/jparest/practice/common/util/TimeBaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package jparest.practice.common.util;

import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

@EntityListeners(AuditingEntityListener.class)
@Getter
@MappedSuperclass
public abstract class TimeBaseEntity {

@CreatedDate
@Column(updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;
}
3 changes: 2 additions & 1 deletion src/main/java/jparest/practice/group/domain/Group.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jparest.practice.group.domain;

import jparest.practice.common.util.TimeBaseEntity;
import jparest.practice.rest.domain.GroupRest;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -14,7 +15,7 @@
@Table(name = "groups")
@Getter
@NoArgsConstructor
public class Group {
public class Group extends TimeBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/jparest/practice/group/domain/UserGroup.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package jparest.practice.group.domain;

import jparest.practice.invite.domain.Invite;
import jparest.practice.common.util.TimeBaseEntity;
import jparest.practice.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Entity
@Table(name = "user_group")
@Getter
@AllArgsConstructor
public class UserGroup {
@NoArgsConstructor
public class UserGroup extends TimeBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/jparest/practice/invite/domain/Invite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package jparest.practice.invite.domain;

import jparest.practice.common.util.TimeBaseEntity;
import jparest.practice.group.domain.UserGroup;
import jparest.practice.invite.exception.AlreadyProcessedInviteException;
import jparest.practice.invite.exception.InviteNotFoundException;
import jparest.practice.user.domain.User;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

import static jparest.practice.invite.domain.InviteStatus.*;

@Entity
@Getter
public class Invite {
@NoArgsConstructor
public class Invite extends TimeBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/jparest/practice/rest/domain/GroupRest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package jparest.practice.rest.domain;

import jparest.practice.common.util.TimeBaseEntity;
import jparest.practice.group.domain.Group;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
public class GroupRest {
@NoArgsConstructor
public class GroupRest extends TimeBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jparest/practice/rest/domain/Rest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jparest.practice.rest.domain;

import jparest.practice.common.util.TimeBaseEntity;
import lombok.*;

import javax.persistence.*;
Expand All @@ -11,7 +12,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Rest {
public class Rest extends TimeBaseEntity {

@Id
@Column(name = "rest_id", nullable = false, length = 16)
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/jparest/practice/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package jparest.practice.user.domain;

import jparest.practice.common.util.TimeBaseEntity;
import jparest.practice.group.domain.UserGroup;
import jparest.practice.invite.domain.Invite;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.ArrayList;
Expand All @@ -18,7 +21,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User {
public class User extends TimeBaseEntity {

@Id
@GeneratedValue(generator = "uuid2")
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spring:
database-platform: org.hibernate.dialect.MySQL8Dialect
open-in-view: true
hibernate:
ddl-auto: create-drop
ddl-auto: update
properties:
hibernate:
show-sql: true
Expand Down

0 comments on commit 7a2cf78

Please sign in to comment.