Skip to content

Commit

Permalink
Merge pull request #7 from team-dodn/spring-lint
Browse files Browse the repository at this point in the history
[lint] change lint to spring-java-format
  • Loading branch information
geminiKim committed Jul 9, 2023
2 parents 27c75dd + 01f32a2 commit 38430a5
Show file tree
Hide file tree
Showing 47 changed files with 136 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

GIT_DIR=$(git rev-parse --show-toplevel)
$GIT_DIR/gradlew spotlessCheck
$GIT_DIR/gradlew checkFormat
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Lint
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: spotlessCheck
arguments: checkFormat
- name: Test
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
Expand Down
1 change: 1 addition & 0 deletions .springjavaformatconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indentation-style=spaces
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ This setting makes it easier to run the `test code` out of the box.
Build, Execution, Deployment > Build Tools > Gradle > Run tests using > IntelliJ IDEA
```

If you want to apply lint settings to the format of IDEA, please refer to the guide below.

[Spring Java Format IntelliJ IDEA](https://github.com/spring-io/spring-javaformat#intellij-idea)

---

# Supported By
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id 'java-library'
id 'org.springframework.boot' apply(false)
id 'io.spring.dependency-management'
id 'io.spring.javaformat' apply(false)
id 'org.asciidoctor.jvm.convert' apply(false)
id 'com.diffplug.spotless' apply(false)
}

apply from: 'lint.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

@FeignClient(value = "example-api", url = "${example.api.url}")
interface ExampleApi {
@RequestMapping(
method = RequestMethod.POST,
value = "/example/example-api",

@RequestMapping(method = RequestMethod.POST, value = "/example/example-api",
consumes = MediaType.APPLICATION_JSON_VALUE)
ExampleResponseDto example(@RequestBody ExampleRequestDto request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Component
public class ExampleClient {

private final ExampleApi exampleApi;

public ExampleClient(ExampleApi exampleApi) {
Expand All @@ -16,4 +17,5 @@ public ExampleClientResult example(String exampleParameter) {
ExampleRequestDto request = new ExampleRequestDto(exampleParameter);
return exampleApi.example(request).toResult();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

@EnableFeignClients
@Configuration
class ExampleConfig {}
class ExampleConfig {

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package io.dodn.springboot.client.example;

record ExampleRequestDto(String exampleRequestValue) {}
record ExampleRequestDto(String exampleRequestValue) {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package io.dodn.springboot.client.example.model;

public record ExampleClientResult(String exampleResult) {}
public record ExampleClientResult(String exampleResult) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
@Tag("context")
@SpringBootTest
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
public abstract class ClientExampleContextTest {}
public abstract class ClientExampleContextTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
@ConfigurationPropertiesScan
@SpringBootApplication
public class ClientExampleTestApplication {

public static void main(String[] args) {
SpringApplication.run(ClientExampleTestApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.Test;

public class ExampleClientTest extends ClientExampleContextTest {

private final ExampleClient exampleClient;

public ExampleClientTest(ExampleClient exampleClient) {
Expand All @@ -19,8 +20,10 @@ public ExampleClientTest(ExampleClient exampleClient) {
public void shouldBeThrownExceptionWhenExample() {
try {
exampleClient.example("HELLO!");
} catch (Exception e) {
}
catch (Exception e) {
assertThat(e).isExactlyInstanceOf(RetryableException.class);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
@ConfigurationPropertiesScan
@SpringBootApplication
public class CoreApiApplication {

public static void main(String[] args) {
SpringApplication.run(CoreApiApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
Expand All @@ -27,4 +28,5 @@ public Executor getAsyncExecutor() {
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new AsyncExceptionHandler();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.Method;

public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {

private final Logger log = LoggerFactory.getLogger(getClass());

@Override
Expand All @@ -19,8 +20,10 @@ public void handleUncaughtException(Throwable e, Method method, Object... params
case WARN -> log.warn("CoreApiException : {}", e.getMessage(), e);
default -> log.info("CoreApiException : {}", e.getMessage(), e);
}
} else {
}
else {
log.error("Exception : {}", e.getMessage(), e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@RestControllerAdvice
public class ApiControllerAdvice {

private final Logger log = LoggerFactory.getLogger(getClass());

@ExceptionHandler(CoreApiException.class)
Expand All @@ -21,14 +22,13 @@ public ResponseEntity<ApiResponse<?>> handleCoreApiException(CoreApiException e)
case WARN -> log.warn("CoreApiException : {}", e.getMessage(), e);
default -> log.info("CoreApiException : {}", e.getMessage(), e);
}
return new ResponseEntity<>(
ApiResponse.error(e.getErrorType(), e.getData()), e.getErrorType().getStatus());
return new ResponseEntity<>(ApiResponse.error(e.getErrorType(), e.getData()), e.getErrorType().getStatus());
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<?>> handleException(Exception e) {
log.error("Exception : {}", e.getMessage(), e);
return new ResponseEntity<>(
ApiResponse.error(ErrorType.DEFAULT_ERROR), ErrorType.DEFAULT_ERROR.getStatus());
return new ResponseEntity<>(ApiResponse.error(ErrorType.DEFAULT_ERROR), ErrorType.DEFAULT_ERROR.getStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

@RestController
public class HealthController {

@GetMapping("/health")
public ResponseEntity<Object> health() {
return ResponseEntity.status(HttpStatus.OK).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

@RestController
public class ExampleController {

private final ExampleService exampleExampleService;

public ExampleController(ExampleService exampleExampleService) {
this.exampleExampleService = exampleExampleService;
}

@GetMapping("/get/{exampleValue}")
public ApiResponse<ExampleResponseDto> exampleGet(
@PathVariable String exampleValue, @RequestParam String exampleParam) {
ExampleResult result =
exampleExampleService.processExample(new ExampleData(exampleValue, exampleParam));
public ApiResponse<ExampleResponseDto> exampleGet(@PathVariable String exampleValue,
@RequestParam String exampleParam) {
ExampleResult result = exampleExampleService.processExample(new ExampleData(exampleValue, exampleParam));
return ApiResponse.success(new ExampleResponseDto(result.data()));
}

Expand All @@ -35,4 +35,5 @@ public ApiResponse<ExampleResponseDto> examplePost(@RequestBody ExampleRequestDt
ExampleResult result = exampleExampleService.processExample(request.toExampleData());
return ApiResponse.success(new ExampleResponseDto(result.data()));
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package io.dodn.springboot.core.api.controller.v1.response;

public record ExampleResponseDto(String result) {}
public record ExampleResponseDto(String result) {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package io.dodn.springboot.core.api.domain;

public record ExampleData(String value, String param) {}
public record ExampleData(String value, String param) {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package io.dodn.springboot.core.api.domain;

public record ExampleResult(String data) {}
public record ExampleResult(String data) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

@Service
public class ExampleService {

public ExampleResult processExample(ExampleData exampleData) {
return new ExampleResult(exampleData.value());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.dodn.springboot.core.api.support.error;

public class CoreApiException extends RuntimeException {

private final ErrorType errorType;

private final Object data;

public CoreApiException(ErrorType errorType, Object data) {
Expand All @@ -17,4 +19,5 @@ public ErrorType getErrorType() {
public Object getData() {
return data;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.dodn.springboot.core.api.support.error;

public enum ErrorCode {

E500

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.dodn.springboot.core.api.support.error;

public class ErrorMessage {

private final String code;

private final String message;

private final Object data;

public ErrorMessage(ErrorType errorType) {
Expand All @@ -28,4 +31,5 @@ public String getMessage() {
public Object getData() {
return data;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import org.springframework.http.HttpStatus;

public enum ErrorType {
DEFAULT_ERROR(
HttpStatus.INTERNAL_SERVER_ERROR,
ErrorCode.E500,
"An unexpected error has occurred.",

DEFAULT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.E500, "An unexpected error has occurred.",
LogLevel.ERROR);

private final HttpStatus status;

private final ErrorCode code;

private final String message;

private final LogLevel logLevel;

ErrorType(HttpStatus status, ErrorCode code, String message, LogLevel logLevel) {
Expand All @@ -38,4 +39,5 @@ public String getMessage() {
public LogLevel getLogLevel() {
return logLevel;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import io.dodn.springboot.core.api.support.error.ErrorType;

public class ApiResponse<S> {

private final ResultType result;

private final S data;

private final ErrorMessage error;

private ApiResponse(ResultType result, S data, ErrorMessage error) {
Expand Down Expand Up @@ -41,4 +44,5 @@ public Object getData() {
public ErrorMessage getError() {
return error;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.dodn.springboot.core.api.support.response;

public enum ResultType {
SUCCESS,
ERROR

SUCCESS, ERROR

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
@Tag("context")
@SpringBootTest
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
public abstract class ContextTest {}
public abstract class ContextTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.junit.jupiter.api.Test;

public class CoreApiApplicationTest extends ContextTest {

@Test
public void shouldBeLoadedContext() {
// it should be passed
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
@Tag("develop")
@SpringBootTest
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
public abstract class DevelopTest {}
public abstract class DevelopTest {

}

0 comments on commit 38430a5

Please sign in to comment.