From e16622dd22bf6fa28b8b9871975d0ee60cbdece9 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Thu, 8 Aug 2024 17:21:00 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20BaseEntity=20=EC=B6=94=EA=B0=80(#51?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/play/pluv/base/BaseEntity.java | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/play/pluv/base/BaseEntity.java diff --git a/src/main/java/play/pluv/base/BaseEntity.java b/src/main/java/play/pluv/base/BaseEntity.java new file mode 100644 index 0000000..1192e51 --- /dev/null +++ b/src/main/java/play/pluv/base/BaseEntity.java @@ -0,0 +1,24 @@ +package play.pluv.base; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import java.time.LocalDateTime; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseEntity { + + @Column(updatable = false, nullable = false) + @CreatedDate + private LocalDateTime createdAt; + + @Column(nullable = false) + @LastModifiedDate + private LocalDateTime updatedAt; +} From 644483943043598f439fb4813045b31be59122e4 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Thu, 8 Aug 2024 17:22:47 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20JpaAuditing=20=ED=99=9C=EC=84=B1?= =?UTF-8?q?=ED=99=94(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/play/pluv/PluvApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/play/pluv/PluvApplication.java b/src/main/java/play/pluv/PluvApplication.java index 0fb5347..a46d815 100644 --- a/src/main/java/play/pluv/PluvApplication.java +++ b/src/main/java/play/pluv/PluvApplication.java @@ -3,8 +3,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication +@EnableJpaAuditing @ConfigurationPropertiesScan public class PluvApplication { From b14d1654cc3c899708532eacde1ffbf3da75ab12 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Thu, 8 Aug 2024 17:23:53 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20LocalDateTime=20seconds=20=EC=A0=88?= =?UTF-8?q?=EC=82=AD(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/play/pluv/PluvApplication.java | 2 +- .../play/pluv/base/LocalDateTimeProvider.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/main/java/play/pluv/base/LocalDateTimeProvider.java diff --git a/src/main/java/play/pluv/PluvApplication.java b/src/main/java/play/pluv/PluvApplication.java index a46d815..239920a 100644 --- a/src/main/java/play/pluv/PluvApplication.java +++ b/src/main/java/play/pluv/PluvApplication.java @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication -@EnableJpaAuditing +@EnableJpaAuditing(dateTimeProviderRef = "localDateTimeProvider") @ConfigurationPropertiesScan public class PluvApplication { diff --git a/src/main/java/play/pluv/base/LocalDateTimeProvider.java b/src/main/java/play/pluv/base/LocalDateTimeProvider.java new file mode 100644 index 0000000..1dbfa55 --- /dev/null +++ b/src/main/java/play/pluv/base/LocalDateTimeProvider.java @@ -0,0 +1,18 @@ +package play.pluv.base; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAccessor; +import java.util.Optional; +import org.springframework.data.auditing.DateTimeProvider; +import org.springframework.stereotype.Component; + +@Component +public class LocalDateTimeProvider implements DateTimeProvider { + + @Override + public Optional getNow() { + return Optional.of(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS)); + } + +} From c467d86890d267165fe103423bdb8d516f55b7a9 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Thu, 8 Aug 2024 18:30:29 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20MvcTest=20=EC=98=B5=EC=85=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/play/pluv/support/ApiTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/test/java/play/pluv/support/ApiTest.java b/src/test/java/play/pluv/support/ApiTest.java index 9fe2f1b..efc2485 100644 --- a/src/test/java/play/pluv/support/ApiTest.java +++ b/src/test/java/play/pluv/support/ApiTest.java @@ -4,30 +4,38 @@ import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; import org.springframework.restdocs.RestDocumentationContextProvider; import org.springframework.restdocs.RestDocumentationExtension; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import play.pluv.base.LocalDateTimeProvider; import play.pluv.login.application.JwtProvider; import play.pluv.login.application.LoginService; import play.pluv.music.application.MusicService; import play.pluv.oauth.application.OAuthService; import play.pluv.playlist.application.PlayListService; +import play.pluv.support.ApiTest.RestDocsResultConfig; @WebMvcTest -@Import(JwtProvider.class) +@Import({JwtProvider.class, RestDocsResultConfig.class}) @ExtendWith({RestDocumentationExtension.class, SpringExtension.class}) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@MockBean(JpaMetamodelMappingContext.class) public abstract class ApiTest { @Autowired @@ -54,4 +62,13 @@ void setUp( .withResponseDefaults(prettyPrint())) .build(); } + + @Configuration + static class RestDocsResultConfig { + + @Bean + public LocalDateTimeProvider localDateTimeProvider() { + return new LocalDateTimeProvider(); + } + } }