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.data.jpa.repository.config.EnableJpaAuditing;
import javax.annotation.PostConstruct;
import java.util.TimeZone;
@SpringBootApplication
public class RealworldApplication {
@PostConstruct
public void setTimeZone() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}
public static void main(String[] args) {
SpringApplication.run(RealworldApplication.class, args);
}

View File

@@ -1,24 +1,36 @@
package com.io.realworld.base.entity;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import javax.persistence.*;
import java.time.ZonedDateTime;
@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class DateEntity {
@CreatedDate
private LocalDateTime createdDate;
@Column(name = "created_at")
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 java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
@Builder
@@ -20,8 +21,8 @@ public class ArticleResponse {
private String body;
private List<String> tagList;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private ZonedDateTime createdAt;
private ZonedDateTime updatedAt;
private Boolean favorited;
private Long favoritesCount;

View File

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

View File

@@ -24,6 +24,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
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.properties.hibernate.format_sql=true
spring.jpq.show-sql=true
#secret
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 java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
@@ -41,7 +42,7 @@ class CommentRepositoryTest {
private User user;
private Article article;
private LocalDateTime beforeCreated;
private ZonedDateTime beforeCreated;
@BeforeEach
void setup(){
@@ -56,7 +57,7 @@ class CommentRepositoryTest {
String title = "create title";
String slug = initSlug(title);
beforeCreated = LocalDateTime.now();
beforeCreated = ZonedDateTime.now();
article = Article.builder()
.author(user)
.body("create body")