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
10 changes: 5 additions & 5 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
- name: Set up JDK 11
uses: actions/setup-java@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: '11'
- uses: actions/cache@v2
java-version: '17'
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ It uses a ~~H2 in-memory database~~ sqlite database (for easy local test without

# Getting started

You'll need Java 11 installed.
You'll need Java 17 installed.

./gradlew bootRun

Expand Down
33 changes: 16 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '2.7.18'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id "com.netflix.dgs.codegen" version "5.0.6"
id "com.diffplug.spotless" version "6.2.1"
id "com.diffplug.spotless" version "6.25.0"
}

version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
targetCompatibility = '11'
sourceCompatibility = '17'
targetCompatibility = '17'

spotless {
java {
Expand All @@ -35,25 +35,24 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
implementation 'com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter:4.9.21'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.2'
implementation 'com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter:5.1.0'
implementation 'org.flywaydb:flyway-core'
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'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5',
'io.jsonwebtoken:jjwt-jackson:0.11.5'
implementation 'org.xerial:sqlite-jdbc:3.42.0.0'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'io.rest-assured:rest-assured:4.5.1'
testImplementation 'io.rest-assured:json-path:4.5.1'
testImplementation 'io.rest-assured:xml-path:4.5.1'
testImplementation 'io.rest-assured:spring-mock-mvc:4.5.1'
testImplementation 'io.rest-assured:rest-assured:5.3.0'
testImplementation 'io.rest-assured:json-path:5.3.0'
testImplementation 'io.rest-assured:xml-path:5.3.0'
testImplementation 'io.rest-assured:spring-mock-mvc:5.3.0'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.2.2'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.3.2'
}

tasks.named('test') {
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/spring/JacksonCustomizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
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.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

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

public static class DateTimeSerializer extends StdSerializer<DateTime> {
public static class DateTimeSerializer extends StdSerializer<LocalDateTime> {

protected DateTimeSerializer() {
super(DateTime.class);
super(LocalDateTime.class);
}

@Override
public void serialize(DateTime value, JsonGenerator gen, SerializerProvider provider)
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
if (value == null) {
gen.writeNull();
} else {
gen.writeString(ISODateTimeFormat.dateTime().withZoneUTC().print(value));
gen.writeString(value.atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
}
}
}
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 @@ -9,6 +9,7 @@
import io.spring.infrastructure.mybatis.readservice.ArticleFavoritesReadService;
import io.spring.infrastructure.mybatis.readservice.ArticleReadService;
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -17,7 +18,6 @@
import java.util.Optional;
import java.util.Set;
import lombok.AllArgsConstructor;
import org.joda.time.DateTime;
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<LocalDateTime> 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<LocalDateTime> 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 @@ -4,14 +4,14 @@
import io.spring.core.user.User;
import io.spring.infrastructure.mybatis.readservice.CommentReadService;
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.joda.time.DateTime;
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<LocalDateTime> page) {
List<CommentData> comments = commentReadService.findByArticleIdWithCursor(articleId, page);
if (comments.isEmpty()) {
return new CursorPager<>(new ArrayList<>(), page.getDirection(), false);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/io/spring/application/DateTimeCursor.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package io.spring.application;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

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

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

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

public static DateTime parse(String cursor) {
public static LocalDateTime parse(String cursor) {
if (cursor == null) {
return null;
}
return new DateTime().withMillis(Long.parseLong(cursor)).withZone(DateTimeZone.UTC);
return LocalDateTime.ofEpochSecond(
Long.parseLong(cursor) / 1000,
(int) ((Long.parseLong(cursor) % 1000) * 1000000),
ZoneOffset.UTC);
}
}
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 @@ -2,11 +2,11 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.spring.application.DateTimeCursor;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;

@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 LocalDateTime createdAt;
private LocalDateTime 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 @@ -4,10 +4,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.spring.application.DateTimeCursor;
import io.spring.application.Node;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;

@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 LocalDateTime createdAt;
private LocalDateTime updatedAt;

@JsonProperty("author")
private ProfileData profileData;
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/io/spring/core/article/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import static java.util.stream.Collectors.toList;

import io.spring.Util;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;

@Getter
@NoArgsConstructor
Expand All @@ -22,12 +23,12 @@ public class Article {
private String description;
private String body;
private List<Tag> tags;
private DateTime createdAt;
private DateTime updatedAt;
private LocalDateTime createdAt;
private LocalDateTime 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, LocalDateTime.now(ZoneOffset.UTC));
}

public Article(
Expand All @@ -36,7 +37,7 @@ public Article(
String body,
List<String> tagList,
String userId,
DateTime createdAt) {
LocalDateTime createdAt) {
this.id = UUID.randomUUID().toString();
this.slug = toSlug(title);
this.title = title;
Expand All @@ -52,15 +53,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 = LocalDateTime.now(ZoneOffset.UTC);
}
if (!Util.isEmpty(description)) {
this.description = description;
this.updatedAt = new DateTime();
this.updatedAt = LocalDateTime.now(ZoneOffset.UTC);
}
if (!Util.isEmpty(body)) {
this.body = body;
this.updatedAt = new DateTime();
this.updatedAt = LocalDateTime.now(ZoneOffset.UTC);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/spring/core/comment/Comment.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.spring.core.comment;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.UUID;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;

@Getter
@NoArgsConstructor
Expand All @@ -14,13 +15,13 @@ public class Comment {
private String body;
private String userId;
private String articleId;
private DateTime createdAt;
private LocalDateTime 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 = LocalDateTime.now(ZoneOffset.UTC);
}
}
15 changes: 12 additions & 3 deletions src/main/java/io/spring/graphql/ArticleDatafetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import io.spring.graphql.types.ArticleEdge;
import io.spring.graphql.types.ArticlesConnection;
import io.spring.graphql.types.Profile;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.joda.time.format.ISODateTimeFormat;

@DgsComponent
@AllArgsConstructor
Expand Down Expand Up @@ -371,14 +372,22 @@ 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(
articleData
.getCreatedAt()
.atOffset(ZoneOffset.UTC)
.format(DateTimeFormatter.ISO_INSTANT))
.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(
articleData
.getUpdatedAt()
.atOffset(ZoneOffset.UTC)
.format(DateTimeFormatter.ISO_INSTANT))
.build();
}
}
Loading