fix : LocalDateTime -> ZoneDateTime because API DOC need **ISO8601** Formatting

This commit is contained in:
kms
2022-11-05 17:37:10 +09:00
parent 0aa4406c0a
commit 9b05b1e67d
8 changed files with 40 additions and 15 deletions

0
doc/run-api-tests.sh Normal file → Executable file
View File

View File

@@ -5,10 +5,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import javax.annotation.PostConstruct;
import java.util.TimeZone;
@SpringBootApplication @SpringBootApplication
public class RealworldApplication { public class RealworldApplication {
@PostConstruct
public void setTimeZone() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(RealworldApplication.class, args); SpringApplication.run(RealworldApplication.class, args);
} }

View File

@@ -1,24 +1,36 @@
package com.io.realworld.base.entity; package com.io.realworld.base.entity;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.EntityListeners; import java.time.ZonedDateTime;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
@Getter @Getter
@Setter
@MappedSuperclass @MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class DateEntity { public class DateEntity {
@CreatedDate @Column(name = "created_at")
private LocalDateTime createdDate; private ZonedDateTime createdDate;
@Column(name = "update_at")
private ZonedDateTime modifiedDate;
@PrePersist
void prePersist() {
this.createdDate = ZonedDateTime.now();
this.modifiedDate = ZonedDateTime.now();
}
@PreUpdate
void preUpdate() {
createdDate = ZonedDateTime.now();
}
@LastModifiedDate
private LocalDateTime modifiedDate;
} }

View File

@@ -7,6 +7,7 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
@Builder @Builder
@@ -20,8 +21,8 @@ public class ArticleResponse {
private String body; private String body;
private List<String> tagList; private List<String> tagList;
private LocalDateTime createdAt; private ZonedDateTime createdAt;
private LocalDateTime updatedAt; private ZonedDateTime updatedAt;
private Boolean favorited; private Boolean favorited;
private Long favoritesCount; private Long favoritesCount;

View File

@@ -6,6 +6,7 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZonedDateTime;
@Builder @Builder
@Getter @Getter
@@ -13,8 +14,8 @@ import java.time.LocalDateTime;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
public class CommentResponse { public class CommentResponse {
private Long id; private Long id;
private LocalDateTime createAt; private ZonedDateTime createAt;
private LocalDateTime updateAt; private ZonedDateTime updateAt;
private String body; private String body;
private Author author; private Author author;

View File

@@ -24,6 +24,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;

View File

@@ -10,6 +10,7 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.format_sql=true
spring.jpq.show-sql=true spring.jpq.show-sql=true
#secret #secret
real-world.token.expiry=3000000 real-world.token.expiry=3000000

View File

@@ -14,6 +14,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -41,7 +42,7 @@ class CommentRepositoryTest {
private User user; private User user;
private Article article; private Article article;
private LocalDateTime beforeCreated; private ZonedDateTime beforeCreated;
@BeforeEach @BeforeEach
void setup(){ void setup(){
@@ -56,7 +57,7 @@ class CommentRepositoryTest {
String title = "create title"; String title = "create title";
String slug = initSlug(title); String slug = initSlug(title);
beforeCreated = LocalDateTime.now(); beforeCreated = ZonedDateTime.now();
article = Article.builder() article = Article.builder()
.author(user) .author(user)
.body("create body") .body("create body")