From 407fb02b61085bc2d09c07743ee409b4f4b02541 Mon Sep 17 00:00:00 2001 From: syyling Date: Thu, 4 Apr 2024 16:50:39 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20BaseTimeEntity=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MookiveBackendApplication.java | 2 ++ .../common/BaseTimeEntity.java | 23 +++++++++++++++++++ .../heart/domain/entity/Heart.java | 3 ++- .../heartPlaylist/domain/HeartPlaylist.java | 3 ++- .../keyword/domain/entity/Keyword.java | 3 ++- .../movie/domain/entity/Movie.java | 3 ++- .../domain/entity/MovieInPlaylist.java | 3 ++- .../playlist/domain/entity/Playlist.java | 3 ++- .../record/domain/entity/Record.java | 3 ++- .../user/domain/entity/User.java | 3 ++- 10 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/mookive/mookive_backend/common/BaseTimeEntity.java diff --git a/src/main/java/com/mookive/mookive_backend/MookiveBackendApplication.java b/src/main/java/com/mookive/mookive_backend/MookiveBackendApplication.java index d96a98b..315584e 100644 --- a/src/main/java/com/mookive/mookive_backend/MookiveBackendApplication.java +++ b/src/main/java/com/mookive/mookive_backend/MookiveBackendApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing @SpringBootApplication public class MookiveBackendApplication { diff --git a/src/main/java/com/mookive/mookive_backend/common/BaseTimeEntity.java b/src/main/java/com/mookive/mookive_backend/common/BaseTimeEntity.java new file mode 100644 index 0000000..962ab8b --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/common/BaseTimeEntity.java @@ -0,0 +1,23 @@ +package com.mookive.mookive_backend.common; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +@Getter +public class BaseTimeEntity { + + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; + +} diff --git a/src/main/java/com/mookive/mookive_backend/heart/domain/entity/Heart.java b/src/main/java/com/mookive/mookive_backend/heart/domain/entity/Heart.java index 3af5d90..75c5b1e 100644 --- a/src/main/java/com/mookive/mookive_backend/heart/domain/entity/Heart.java +++ b/src/main/java/com/mookive/mookive_backend/heart/domain/entity/Heart.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.heart.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import com.mookive.mookive_backend.movie.domain.entity.Movie; import com.mookive.mookive_backend.user.domain.entity.User; import jakarta.persistence.*; @@ -11,7 +12,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Heart { +public class Heart extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/heartPlaylist/domain/HeartPlaylist.java b/src/main/java/com/mookive/mookive_backend/heartPlaylist/domain/HeartPlaylist.java index 30e5edd..4f54801 100644 --- a/src/main/java/com/mookive/mookive_backend/heartPlaylist/domain/HeartPlaylist.java +++ b/src/main/java/com/mookive/mookive_backend/heartPlaylist/domain/HeartPlaylist.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.heartPlaylist.domain; +import com.mookive.mookive_backend.common.BaseTimeEntity; import com.mookive.mookive_backend.playlist.domain.entity.Playlist; import com.mookive.mookive_backend.user.domain.entity.User; import jakarta.persistence.*; @@ -11,7 +12,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class HeartPlaylist { +public class HeartPlaylist extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java b/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java index 02e7b34..8659c78 100644 --- a/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java +++ b/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.keyword.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import com.mookive.mookive_backend.record.domain.entity.Record; import jakarta.persistence.*; import lombok.AccessLevel; @@ -10,7 +11,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Keyword { +public class Keyword extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java b/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java index 6cb4ffb..af9d0a2 100644 --- a/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java +++ b/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.movie.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -9,7 +10,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Movie { +public class Movie extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/entity/MovieInPlaylist.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/entity/MovieInPlaylist.java index 86511cf..e682aa4 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/entity/MovieInPlaylist.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/entity/MovieInPlaylist.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.movieInPlaylist.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import com.mookive.mookive_backend.movie.domain.entity.Movie; import com.mookive.mookive_backend.playlist.domain.entity.Playlist; import jakarta.persistence.*; @@ -11,7 +12,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class MovieInPlaylist { +public class MovieInPlaylist extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/playlist/domain/entity/Playlist.java b/src/main/java/com/mookive/mookive_backend/playlist/domain/entity/Playlist.java index 6118fdd..a74aa5c 100644 --- a/src/main/java/com/mookive/mookive_backend/playlist/domain/entity/Playlist.java +++ b/src/main/java/com/mookive/mookive_backend/playlist/domain/entity/Playlist.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.playlist.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; import com.mookive.mookive_backend.user.domain.entity.User; import jakarta.persistence.*; @@ -14,7 +15,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Playlist { +public class Playlist extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java b/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java index a23dd8f..79c2dcb 100644 --- a/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java +++ b/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java @@ -1,6 +1,7 @@ package com.mookive.mookive_backend.record.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import com.mookive.mookive_backend.movie.domain.entity.Movie; import com.mookive.mookive_backend.user.domain.entity.User; import jakarta.persistence.*; @@ -14,7 +15,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Record { +public class Record extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java b/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java index c85583e..8566cda 100644 --- a/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java +++ b/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.user.domain.entity; +import com.mookive.mookive_backend.common.BaseTimeEntity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -12,7 +13,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class User { +public class User extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;