Skip to content

Commit

Permalink
[#13] chore: 구글 자바 포맷 들여쓰기 2칸으로 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
NaMinhyeok committed Jan 25, 2025
1 parent 70a8f53 commit 3e5fa38
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 269 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ subprojects{
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
googleJavaFormat().aosp()
googleJavaFormat()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,60 @@

public class P6SpyFormatter implements MessageFormattingStrategy {

@Override
public String formatMessage(
int connectionId,
String now,
long elapsed,
String category,
String prepared,
String sql,
String url) {
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
String callStack = findCallingClass(stackTrace);
@Override
public String formatMessage(
int connectionId,
String now,
long elapsed,
String category,
String prepared,
String sql,
String url) {
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
String callStack = findCallingClass(stackTrace);

if ("commit".equalsIgnoreCase(category) || "rollback".equalsIgnoreCase(category)) {
return String.format(
"\n\n ======================================== 트랜잭션 정보 ========================================\n"
+ " # 시간: %s\n"
+ " # 동작: %s\n"
+ " # 호출 위치: %s\n"
+ " ===============================================================================================\n",
now, category, callStack);
}

return String.format(
"\n\n ======================================== P6Spy SQL 로그 ========================================\n"
+ " # 요청 시간: %s\n"
+ " # 실행 시간: %dms\n"
+ " # 카테고리: %s\n"
+ " # 호출 위치: %s\n"
+ " # SQL: \n%s\n"
+ " ===============================================================================================\n",
now, elapsed, category, callStack, formatSql(sql));
if ("commit".equalsIgnoreCase(category) || "rollback".equalsIgnoreCase(category)) {
return String.format(
"\n\n ======================================== 트랜잭션 정보 ========================================\n"
+ " # 시간: %s\n"
+ " # 동작: %s\n"
+ " # 호출 위치: %s\n"
+ " ===============================================================================================\n",
now, category, callStack);
}

private String findCallingClass(StackTraceElement[] stackTrace) {
return Arrays.stream(stackTrace)
.filter(
element ->
element.getClassName().contains("org.nexters")
&& !element.getClassName().contains("P6SpyFormatter")
&& !element.getClassName().contains("$Proxy"))
.findFirst()
.map(element -> element.getClassName() + "." + element.getMethodName())
.orElse("Unknown");
}
return String.format(
"\n\n ======================================== P6Spy SQL 로그 ========================================\n"
+ " # 요청 시간: %s\n"
+ " # 실행 시간: %dms\n"
+ " # 카테고리: %s\n"
+ " # 호출 위치: %s\n"
+ " # SQL: \n%s\n"
+ " ===============================================================================================\n",
now, elapsed, category, callStack, formatSql(sql));
}

private String formatSql(String sql) {
if (sql == null || sql.trim().isEmpty()) {
return sql;
}
String formattedSql = SqlFormatter.format(sql);
private String findCallingClass(StackTraceElement[] stackTrace) {
return Arrays.stream(stackTrace)
.filter(
element ->
element.getClassName().contains("org.nexters")
&& !element.getClassName().contains("P6SpyFormatter")
&& !element.getClassName().contains("$Proxy"))
.findFirst()
.map(element -> element.getClassName() + "." + element.getMethodName())
.orElse("Unknown");
}

return Arrays.stream(formattedSql.split("\n"))
.map(line -> "\t\t" + line) // 들여쓰기 추가
.reduce((a, b) -> a + "\n" + b)
.orElse("");
private String formatSql(String sql) {
if (sql == null || sql.trim().isEmpty()) {
return sql;
}
String formattedSql = SqlFormatter.format(sql);

return Arrays.stream(formattedSql.split("\n"))
.map(line -> "\t\t" + line) // 들여쓰기 추가
.reduce((a, b) -> a + "\n" + b)
.orElse("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
@Getter
public class CustomException extends RuntimeException {

public static final CustomException SAMPLE_NOT_FOUND =
new CustomException(ErrorType.SAMPLE_NOT_FOUND);
public static final CustomException SAMPLE_NOT_FOUND =
new CustomException(ErrorType.SAMPLE_NOT_FOUND);

private final ErrorType errorType;
private final ErrorType errorType;

private final Object data;
private final Object data;

public CustomException(ErrorType errorType) {
super(errorType.getMessage());
this.errorType = errorType;
this.data = null;
}
public CustomException(ErrorType errorType) {
super(errorType.getMessage());
this.errorType = errorType;
this.data = null;
}

public CustomException(ErrorType errorType, Object data) {
super(errorType.getMessage());
this.errorType = errorType;
this.data = data;
}
public CustomException(ErrorType errorType, Object data) {
super(errorType.getMessage());
this.errorType = errorType;
this.data = data;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.nexters.jaknaesocore.common.support.error;

public enum ErrorCode {
E500,
E400,
E404
E500,
E400,
E404
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
@Getter
public class ErrorMessage {

private final String code;
private final String code;

private final String message;
private final String message;

private final Object data;
private final Object data;

public ErrorMessage(ErrorType errorType) {
this.code = errorType.getCode().name();
this.message = errorType.getMessage();
this.data = null;
}
public ErrorMessage(ErrorType errorType) {
this.code = errorType.getCode().name();
this.message = errorType.getMessage();
this.data = null;
}

public ErrorMessage(ErrorType errorType, Object data) {
this.code = errorType.getCode().name();
this.message = errorType.getMessage();
this.data = data;
}
public ErrorMessage(ErrorType errorType, Object data) {
this.code = errorType.getCode().name();
this.message = errorType.getMessage();
this.data = data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@

@Getter
public enum ErrorType {
DEFAULT_ERROR(
HttpStatus.INTERNAL_SERVER_ERROR,
ErrorCode.E500,
"An unexpected error has occurred.",
LogLevel.ERROR),
METHOD_ARGUMENT_NOT_VALID(
HttpStatus.BAD_REQUEST,
ErrorCode.E400,
"Method argument validation failed.",
LogLevel.DEBUG),
BINDING_ERROR(HttpStatus.BAD_REQUEST, ErrorCode.E400, "Data binding failed.", LogLevel.WARN),
SAMPLE_NOT_FOUND(HttpStatus.NOT_FOUND, ErrorCode.E404, "Sample not found.", LogLevel.WARN),
;
DEFAULT_ERROR(
HttpStatus.INTERNAL_SERVER_ERROR,
ErrorCode.E500,
"An unexpected error has occurred.",
LogLevel.ERROR),
METHOD_ARGUMENT_NOT_VALID(
HttpStatus.BAD_REQUEST, ErrorCode.E400, "Method argument validation failed.", LogLevel.DEBUG),
BINDING_ERROR(HttpStatus.BAD_REQUEST, ErrorCode.E400, "Data binding failed.", LogLevel.WARN),
SAMPLE_NOT_FOUND(HttpStatus.NOT_FOUND, ErrorCode.E404, "Sample not found.", LogLevel.WARN),
;

private final HttpStatus status;
private final HttpStatus status;

private final ErrorCode code;
private final ErrorCode code;

private final String message;
private final String message;

private final LogLevel logLevel;
private final LogLevel logLevel;

ErrorType(HttpStatus status, ErrorCode code, String message, LogLevel logLevel) {
this.status = status;
this.code = code;
this.message = message;
this.logLevel = logLevel;
}
ErrorType(HttpStatus status, ErrorCode code, String message, LogLevel logLevel) {
this.status = status;
this.code = code;
this.message = message;
this.logLevel = logLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@

@Getter
public class ApiResponse<S> {
private final ResultType result;
private final ResultType result;

private final S data;
private final S data;

private final ErrorMessage error;
private final ErrorMessage error;

private ApiResponse(ResultType result, S data, ErrorMessage error) {
this.result = result;
this.data = data;
this.error = error;
}
private ApiResponse(ResultType result, S data, ErrorMessage error) {
this.result = result;
this.data = data;
this.error = error;
}

public static ApiResponse<?> success() {
return new ApiResponse<>(ResultType.SUCCESS, null, null);
}
public static ApiResponse<?> success() {
return new ApiResponse<>(ResultType.SUCCESS, null, null);
}

public static <S> ApiResponse<S> success(S data) {
return new ApiResponse<>(ResultType.SUCCESS, data, null);
}
public static <S> ApiResponse<S> success(S data) {
return new ApiResponse<>(ResultType.SUCCESS, data, null);
}

public static ApiResponse<?> error(ErrorType error) {
return new ApiResponse<>(ResultType.ERROR, null, new ErrorMessage(error));
}
public static ApiResponse<?> error(ErrorType error) {
return new ApiResponse<>(ResultType.ERROR, null, new ErrorMessage(error));
}

public static ApiResponse<?> error(ErrorType error, Object errorData) {
return new ApiResponse<>(ResultType.ERROR, null, new ErrorMessage(error, errorData));
}
public static ApiResponse<?> error(ErrorType error, Object errorData) {
return new ApiResponse<>(ResultType.ERROR, null, new ErrorMessage(error, errorData));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.nexters.jaknaesocore.common.support.response;

public enum ResultType {
SUCCESS,
ERROR
SUCCESS,
ERROR
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Sample {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
private Long id;

private String name;
private String name;

private Sample(final String name) {
this.name = name;
}
private Sample(final String name) {
this.name = name;
}

public static Sample of() {
final String name = "name";
return new Sample(name);
}
public static Sample of() {
final String name = "name";
return new Sample(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
@RequiredArgsConstructor
public class SampleService {

private final SampleJpaRepository sampleJpaRepository;
private final SampleJpaRepository sampleJpaRepository;

@Transactional
public Long save() {
return sampleJpaRepository.save(Sample.of()).getId();
}
@Transactional
public Long save() {
return sampleJpaRepository.save(Sample.of()).getId();
}

@Transactional(readOnly = true)
public Long getBy(final Long sampleId) {
return sampleJpaRepository
.findById(sampleId)
.orElseThrow(() -> CustomException.SAMPLE_NOT_FOUND)
.getId();
}
@Transactional(readOnly = true)
public Long getBy(final Long sampleId) {
return sampleJpaRepository
.findById(sampleId)
.orElseThrow(() -> CustomException.SAMPLE_NOT_FOUND)
.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@SpringBootApplication(scanBasePackages = "org.nexters")
public class JaknaesoserverApplication {

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

0 comments on commit 3e5fa38

Please sign in to comment.