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@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: '11'
- uses: actions/cache@v2
java-version: '17'
- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand Down
21 changes: 10 additions & 11 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"
}

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

spotless {
java {
Expand All @@ -35,14 +35,13 @@ 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 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.2'
implementation 'com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter:4.9.21'
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.1'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -53,7 +52,7 @@ dependencies {
testImplementation 'io.rest-assured:spring-mock-mvc:4.5.1'
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
20 changes: 12 additions & 8 deletions src/main/java/io/spring/JacksonCustomizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,42 @@
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.ZoneOffset;
import java.time.format.DateTimeFormatter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JacksonCustomizations {

private static final DateTimeFormatter ISO_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneOffset.UTC);

@Bean
public Module realWorldModules() {
return new 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(ISO_FORMATTER.format(value));
}
}
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/io/spring/api/security/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
Expand All @@ -20,7 +20,7 @@

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public class WebSecurityConfig {

@Bean
public JwtTokenFilter jwtTokenFilter() {
Expand All @@ -32,9 +32,8 @@ public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Override
protected void configure(HttpSecurity http) throws Exception {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf()
.disable()
.cors()
Expand Down Expand Up @@ -62,19 +61,15 @@ protected void configure(HttpSecurity http) throws Exception {
.authenticated();

http.addFilterBefore(jwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
return http.build();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
final CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(asList("*"));
configuration.setAllowedMethods(asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
// setAllowCredentials(true) is important, otherwise:
// The value of the 'Access-Control-Allow-Origin' header in the response must not be the
// wildcard '*' when the request's credentials mode is 'include'.
configuration.setAllowCredentials(false);
// setAllowedHeaders is important! Without it, OPTIONS preflight request
// will fail with 403 Invalid CORS request
configuration.setAllowedHeaders(asList("Authorization", "Cache-Control", "Content-Type"));
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
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();
}
}
7 changes: 4 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,8 @@
import java.util.HashMap;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.joda.time.format.ISODateTimeFormat;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

@DgsComponent
@AllArgsConstructor
Expand Down Expand Up @@ -371,14 +372,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.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneOffset.UTC).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.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneOffset.UTC).format(articleData.getUpdatedAt()))
.build();
}
}
Loading