Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: '11'
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2',
'io.jsonwebtoken:jjwt-jackson:0.11.2'
implementation 'joda-time:joda-time:2.10.13'
implementation 'org.xerial:sqlite-jdbc:3.36.0.3'

compileOnly 'org.projectlombok:lombok'
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/spring/JacksonCustomizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -21,23 +21,23 @@ public Module realWorldModules() {

public static class RealWorldModules extends SimpleModule {
public RealWorldModules() {
addSerializer(DateTime.class, new DateTimeSerializer());
addSerializer(Instant.class, new InstantSerializer());
}
}

public static class DateTimeSerializer extends StdSerializer<DateTime> {
public static class InstantSerializer extends StdSerializer<Instant> {

protected DateTimeSerializer() {
super(DateTime.class);
protected InstantSerializer() {
super(Instant.class);
}

@Override
public void serialize(DateTime value, JsonGenerator gen, SerializerProvider provider)
public void serialize(Instant value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
if (value == null) {
gen.writeNull();
} else {
gen.writeString(ISODateTimeFormat.dateTime().withZoneUTC().print(value));
gen.writeString(DateTimeFormatter.ISO_INSTANT.format(value));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/spring/application/ArticleQueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Optional;
import java.util.Set;
import lombok.AllArgsConstructor;
import org.joda.time.DateTime;
import java.time.Instant;
import org.springframework.stereotype.Service;

@Service
Expand Down Expand Up @@ -55,7 +55,7 @@ public CursorPager<ArticleData> findRecentArticlesWithCursor(
String tag,
String author,
String favoritedBy,
CursorPageParameter<DateTime> page,
CursorPageParameter<Instant> page,
User currentUser) {
List<String> articleIds =
articleReadService.findArticlesWithCursor(tag, author, favoritedBy, page);
Expand All @@ -78,7 +78,7 @@ public CursorPager<ArticleData> findRecentArticlesWithCursor(
}

public CursorPager<ArticleData> findUserFeedWithCursor(
User user, CursorPageParameter<DateTime> page) {
User user, CursorPageParameter<Instant> page) {
List<String> followdUsers = userRelationshipQueryService.followedUsers(user.getId());
if (followdUsers.size() == 0) {
return new CursorPager<>(new ArrayList<>(), page.getDirection(), false);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/spring/application/CommentQueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.joda.time.DateTime;
import java.time.Instant;
import org.springframework.stereotype.Service;

@Service
Expand Down Expand Up @@ -54,7 +54,7 @@ public List<CommentData> findByArticleId(String articleId, User user) {
}

public CursorPager<CommentData> findByArticleIdWithCursor(
String articleId, User user, CursorPageParameter<DateTime> page) {
String articleId, User user, CursorPageParameter<Instant> page) {
List<CommentData> comments = commentReadService.findByArticleIdWithCursor(articleId, page);
if (comments.isEmpty()) {
return new CursorPager<>(new ArrayList<>(), page.getDirection(), false);
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/io/spring/application/DateTimeCursor.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package io.spring.application;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.time.Instant;

public class DateTimeCursor extends PageCursor<DateTime> {
public class DateTimeCursor extends PageCursor<Instant> {

public DateTimeCursor(DateTime data) {
public DateTimeCursor(Instant data) {
super(data);
}

@Override
public String toString() {
return String.valueOf(getData().getMillis());
return String.valueOf(getData().toEpochMilli());
}

public static DateTime parse(String cursor) {
public static Instant parse(String cursor) {
if (cursor == null) {
return null;
}
return new DateTime().withMillis(Long.parseLong(cursor)).withZone(DateTimeZone.UTC);
return Instant.ofEpochMilli(Long.parseLong(cursor));
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/spring/application/data/ArticleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;
import java.time.Instant;

@Data
@NoArgsConstructor
Expand All @@ -19,8 +19,8 @@ public class ArticleData implements io.spring.application.Node {
private String body;
private boolean favorited;
private int favoritesCount;
private DateTime createdAt;
private DateTime updatedAt;
private Instant createdAt;
private Instant updatedAt;
private List<String> tagList;

@JsonProperty("author")
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/spring/application/data/CommentData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;
import java.time.Instant;

@Data
@NoArgsConstructor
Expand All @@ -16,8 +16,8 @@ public class CommentData implements Node {
private String id;
private String body;
@JsonIgnore private String articleId;
private DateTime createdAt;
private DateTime updatedAt;
private Instant createdAt;
private Instant updatedAt;

@JsonProperty("author")
private ProfileData profileData;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/spring/core/article/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;
import java.time.Instant;

@Getter
@NoArgsConstructor
Expand All @@ -22,12 +22,12 @@ public class Article {
private String description;
private String body;
private List<Tag> tags;
private DateTime createdAt;
private DateTime updatedAt;
private Instant createdAt;
private Instant updatedAt;

public Article(
String title, String description, String body, List<String> tagList, String userId) {
this(title, description, body, tagList, userId, new DateTime());
this(title, description, body, tagList, userId, Instant.now());
}

public Article(
Expand All @@ -36,7 +36,7 @@ public Article(
String body,
List<String> tagList,
String userId,
DateTime createdAt) {
Instant createdAt) {
this.id = UUID.randomUUID().toString();
this.slug = toSlug(title);
this.title = title;
Expand All @@ -52,15 +52,15 @@ public void update(String title, String description, String body) {
if (!Util.isEmpty(title)) {
this.title = title;
this.slug = toSlug(title);
this.updatedAt = new DateTime();
this.updatedAt = Instant.now();
}
if (!Util.isEmpty(description)) {
this.description = description;
this.updatedAt = new DateTime();
this.updatedAt = Instant.now();
}
if (!Util.isEmpty(body)) {
this.body = body;
this.updatedAt = new DateTime();
this.updatedAt = Instant.now();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/spring/core/comment/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;
import java.time.Instant;

@Getter
@NoArgsConstructor
Expand All @@ -14,13 +14,13 @@ public class Comment {
private String body;
private String userId;
private String articleId;
private DateTime createdAt;
private Instant createdAt;

public Comment(String body, String userId, String articleId) {
this.id = UUID.randomUUID().toString();
this.body = body;
this.userId = userId;
this.articleId = articleId;
this.createdAt = new DateTime();
this.createdAt = Instant.now();
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/spring/graphql/ArticleDatafetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.HashMap;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.joda.time.format.ISODateTimeFormat;
import java.time.format.DateTimeFormatter;

@DgsComponent
@AllArgsConstructor
Expand Down Expand Up @@ -371,14 +371,14 @@ private DefaultPageInfo buildArticlePageInfo(CursorPager<ArticleData> articles)
private Article buildArticleResult(ArticleData articleData) {
return Article.newBuilder()
.body(articleData.getBody())
.createdAt(ISODateTimeFormat.dateTime().withZoneUTC().print(articleData.getCreatedAt()))
.createdAt(DateTimeFormatter.ISO_INSTANT.format(articleData.getCreatedAt()))
.description(articleData.getDescription())
.favorited(articleData.isFavorited())
.favoritesCount(articleData.getFavoritesCount())
.slug(articleData.getSlug())
.tagList(articleData.getTagList())
.title(articleData.getTitle())
.updatedAt(ISODateTimeFormat.dateTime().withZoneUTC().print(articleData.getUpdatedAt()))
.updatedAt(DateTimeFormatter.ISO_INSTANT.format(articleData.getUpdatedAt()))
.build();
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/spring/graphql/CommentDatafetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.joda.time.format.ISODateTimeFormat;
import java.time.format.DateTimeFormatter;

@DgsComponent
@AllArgsConstructor
Expand Down Expand Up @@ -115,8 +115,8 @@ private Comment buildCommentResult(CommentData comment) {
return Comment.newBuilder()
.id(comment.getId())
.body(comment.getBody())
.updatedAt(ISODateTimeFormat.dateTime().withZoneUTC().print(comment.getCreatedAt()))
.createdAt(ISODateTimeFormat.dateTime().withZoneUTC().print(comment.getCreatedAt()))
.updatedAt(DateTimeFormatter.ISO_INSTANT.format(comment.getCreatedAt()))
.createdAt(DateTimeFormatter.ISO_INSTANT.format(comment.getCreatedAt()))
.build();
}
}
22 changes: 11 additions & 11 deletions src/main/java/io/spring/infrastructure/mybatis/DateTimeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.Calendar;
import java.util.TimeZone;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;
import org.joda.time.DateTime;

@MappedTypes(DateTime.class)
public class DateTimeHandler implements TypeHandler<DateTime> {
@MappedTypes(Instant.class)
public class DateTimeHandler implements TypeHandler<Instant> {

private static final Calendar UTC_CALENDAR = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

@Override
public void setParameter(PreparedStatement ps, int i, DateTime parameter, JdbcType jdbcType)
public void setParameter(PreparedStatement ps, int i, Instant parameter, JdbcType jdbcType)
throws SQLException {
ps.setTimestamp(
i, parameter != null ? new Timestamp(parameter.getMillis()) : null, UTC_CALENDAR);
i, parameter != null ? Timestamp.from(parameter) : null, UTC_CALENDAR);
}

@Override
public DateTime getResult(ResultSet rs, String columnName) throws SQLException {
public Instant getResult(ResultSet rs, String columnName) throws SQLException {
Timestamp timestamp = rs.getTimestamp(columnName, UTC_CALENDAR);
return timestamp != null ? new DateTime(timestamp.getTime()) : null;
return timestamp != null ? timestamp.toInstant() : null;
}

@Override
public DateTime getResult(ResultSet rs, int columnIndex) throws SQLException {
public Instant getResult(ResultSet rs, int columnIndex) throws SQLException {
Timestamp timestamp = rs.getTimestamp(columnIndex, UTC_CALENDAR);
return timestamp != null ? new DateTime(timestamp.getTime()) : null;
return timestamp != null ? timestamp.toInstant() : null;
}

@Override
public DateTime getResult(CallableStatement cs, int columnIndex) throws SQLException {
public Instant getResult(CallableStatement cs, int columnIndex) throws SQLException {
Timestamp ts = cs.getTimestamp(columnIndex, UTC_CALENDAR);
return ts != null ? new DateTime(ts.getTime()) : null;
return ts != null ? ts.toInstant() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.joda.time.DateTime;
import java.time.Instant;

@Mapper
public interface CommentReadService {
Expand All @@ -14,5 +14,5 @@ public interface CommentReadService {
List<CommentData> findByArticleId(@Param("articleId") String articleId);

List<CommentData> findByArticleIdWithCursor(
@Param("articleId") String articleId, @Param("page") CursorPageParameter<DateTime> page);
@Param("articleId") String articleId, @Param("page") CursorPageParameter<Instant> page);
}
4 changes: 2 additions & 2 deletions src/test/java/io/spring/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import io.spring.core.user.User;
import java.util.ArrayList;
import java.util.Arrays;
import org.joda.time.DateTime;
import java.time.Instant;

public class TestHelper {
public static ArticleData articleDataFixture(String seed, User user) {
DateTime now = new DateTime();
Instant now = Instant.now();
return new ArticleData(
seed + "id",
"title-" + seed,
Expand Down
Loading