Skip to content

Commit

Permalink
chore: Spotless 코드 포맷팅 + pre-commit 스크립트 작성 (#4)
Browse files Browse the repository at this point in the history
* chore : spotless 설정

* chore : spotless 컨벤션 적용

* chore : spotless pre-commit 적용

* chore : spotless 자바 포맷 변경

* chore : 자바 컨벤션 적용
  • Loading branch information
cowboysj authored and LeeHanEum committed Jan 30, 2025
1 parent 0cf8bcf commit 7dd98d6
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 67 deletions.
36 changes: 36 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.4.2'
id 'io.spring.dependency-management' version '1.1.7'
id 'com.diffplug.spotless' version '6.20.0'
}

group = 'depromeet'
Expand All @@ -26,3 +27,38 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}
spotless {
java {
// Import 순서
importOrder("java", "javax", "jakarta", "org", "com")
// 사용하지 않는 import 자동 제거
removeUnusedImports()
//구글 자바 포맷 적용
googleJavaFormat()
// 파일 끝에 개행 추가
endWithNewline()
// 각 라인 끝에 공백 제거
trimTrailingWhitespace()
// 애노테이션 포맷팅 정리 (한 줄에 한 개씩 배치)
formatAnnotations()
}
}

tasks.register("updateGitHooks", Copy) {
from(file("${rootProject.rootDir}/scripts/pre-commit"))
into(file("${rootProject.rootDir}/.git/hooks"))
}

tasks.register('makeGitHooksExecutable', Exec) {
if (System.getProperty("os.name").contains("Windows")) {
commandLine("attrib", "+x", "${rootProject.rootDir}/.git/hooks/pre-commit")
} else {
commandLine("chmod", "+x", "${rootProject.rootDir}/.git/hooks/pre-commit")
}
dependsOn("updateGitHooks")
}

tasks.withType(JavaCompile) {
dependsOn("makeGitHooksExecutable")
}

19 changes: 19 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

PROJECT_ROOT=$(git rev-parse --show-toplevel)

stagedFiles=$(git diff --staged --name-only)

echo "Running spotlessApply. Formatting code..."
cd $PROJECT_ROOT && ./gradlew spotlessApply

if [ $? -ne 0 ]; then
echo "Spotless apply failed!"
exit 1
fi

for file in $stagedFiles; do
if test -f "$file"; then
git add $file
fi
done
7 changes: 3 additions & 4 deletions src/main/java/depromeet/onepiece/OnepieceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@SpringBootApplication
public class OnepieceApplication {

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

public static void main(String[] args) {
SpringApplication.run(OnepieceApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package depromeet.onepiece.payment.command.application;

/**
* 도메인 주도 개발 아키텍처에서 application 계층은 도메인 규칙에 핵심 로직 수행을 위임해요.
* 도메인 객체를 조합하고, 도메인 객체 간의 흐름을 제어하며, 도메인 객체의 상태를 변경하는 역할을 합니다.
* 꼭 CommandService라고 명명할 필요는 없지만, 명령을 처리하는 역할을 하는 서비스라는 것을 알 수 있도록 이름을 지어주는 것이 좋아요.
* 도메인 주도 개발 아키텍처에서 application 계층은 도메인 규칙에 핵심 로직 수행을 위임해요. 도메인 객체를 조합하고, 도메인 객체 간의 흐름을 제어하며, 도메인
* 객체의 상태를 변경하는 역할을 합니다. 꼭 CommandService라고 명명할 필요는 없지만, 명령을 처리하는 역할을 하는 서비스라는 것을 알 수 있도록 이름을 지어주는
* 것이 좋아요.
*/
public class PaymentCommandService {
}
public class PaymentCommandService {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package depromeet.onepiece.payment.command.application.exception;

/**
* CommandExceptionCode는 CommandService에서 발생하는 커스텀 예외 코드를 정의해요.
*/
public enum PaymentCommandExceptionCode {
}
/** CommandExceptionCode는 CommandService에서 발생하는 커스텀 예외 코드를 정의해요. */
public enum PaymentCommandExceptionCode {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package depromeet.onepiece.payment.command.domain;

/**
* 도메인 주도 개발 DDD 아키텍처에서는 CommandRepository 별도로 구현하여 CQRS 패턴을 적용합니다.
* Master-Slave 구조에서는 Master DB에 쓰기 작업을 하고, Slave DB에서 읽기 작업을 하기 때문에, CommandRepository를 별도로 구현해요.
* 도메인 주도 개발 DDD 아키텍처에서는 CommandRepository 별도로 구현하여 CQRS 패턴을 적용합니다. Master-Slave 구조에서는 Master DB에 쓰기
* 작업을 하고, Slave DB에서 읽기 작업을 하기 때문에, CommandRepository를 별도로 구현해요.
*/
public interface PaymentCommandRepository {
}
public interface PaymentCommandRepository {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package depromeet.onepiece.payment.command.infrastructure;

/**
* RepositoryImpl은 Repository 인터페이스를 구현한 클래스로, 실제로 데이터베이스에 접근하여 데이터를 저장하거나 조회하는 역할을 해요.
* 데이터베이스 접근 기술(JPA DATA, QueryDSL, MyBatis 등)을 사용하여 구현합니다.
* 만약 JPA 및 QueryDSL을 사용한다면, infrastructure 패키지 내에 PaymentCommandJpaRepository, PaymentCommandQueryDslRepository 같이 구현 클래스를 생성할 수 있어요.
* RepositoryImpl은 Repository 인터페이스를 구현한 클래스로, 실제로 데이터베이스에 접근하여 데이터를 저장하거나 조회하는 역할을 해요. 데이터베이스 접근
* 기술(JPA DATA, QueryDSL, MyBatis 등)을 사용하여 구현합니다. 만약 JPA 및 QueryDSL을 사용한다면, infrastructure 패키지 내에
* PaymentCommandJpaRepository, PaymentCommandQueryDslRepository 같이 구현 클래스를 생성할 수 있어요.
*/
public class PaymentCommandRepositoryImpl {
}
public class PaymentCommandRepositoryImpl {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package depromeet.onepiece.payment.command.presentation;

/**
* 도메인 간 의존성을 제거하고 이벤트 소싱을 적용하기 위해 CQRS 패턴을 적용해요.
* CQRS 패턴은 명령(Command)과 조회(Query)를 분리하는 패턴으로, 이 중에서 명령(Command)은 상태를 변경하는 역할을 담당해요.
* 꼭 CommandController라고 명명할 필요는 없지만, 명령을 처리하는 역할을 하는 컨트롤러라는 것을 알 수 있도록 이름을 지어주는 것이 좋아요.
* 도메인 간 의존성을 제거하고 이벤트 소싱을 적용하기 위해 CQRS 패턴을 적용해요. CQRS 패턴은 명령(Command)과 조회(Query)를 분리하는 패턴으로, 이 중에서
* 명령(Command)은 상태를 변경하는 역할을 담당해요. 꼭 CommandController라고 명명할 필요는 없지만, 명령을 처리하는 역할을 하는 컨트롤러라는 것을 알 수
* 있도록 이름을 지어주는 것이 좋아요.
*/
public class PaymentCommandController {
}
public class PaymentCommandController {}
11 changes: 4 additions & 7 deletions src/main/java/depromeet/onepiece/payment/domain/Payment.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package depromeet.onepiece.payment.domain;

/**
* 도메인 주도 개발 DDD 아키텍처에서는 비즈니스 로직을 도메인 객체에 위치 시킵니다.
* 이것을 도메인 규칙이라고 부르며, 외부에서 객체에 접근할 때는 이 도메인 규칙을 통해 객체의 상태를 변경해야 해요.
* 도메인 규칙은 한 트랜잭션 안에서 처리할 수 있는 작은 단위로 나누는 것이 좋습니다.
* 흔히 비슷한 도메인을 묶어서 하나의 애그리거트로 처리하기도 하지만, 도메인 간 복잡성을 증가시키고 일관성을 깨트릴 수 있으므로 주의해야 해요.
* 도메인 주도 개발 DDD 아키텍처에서는 비즈니스 로직을 도메인 객체에 위치 시킵니다. 이것을 도메인 규칙이라고 부르며, 외부에서 객체에 접근할 때는 이 도메인 규칙을 통해
* 객체의 상태를 변경해야 해요. 도메인 규칙은 한 트랜잭션 안에서 처리할 수 있는 작은 단위로 나누는 것이 좋습니다. 흔히 비슷한 도메인을 묶어서 하나의 애그리거트로 처리하기도
* 하지만, 도메인 간 복잡성을 증가시키고 일관성을 깨트릴 수 있으므로 주의해야 해요.
*/

public class Payment {
}
public class Payment {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package depromeet.onepiece.payment.domain.exception;

/**
* DomainExceptionCode는 도메인 규칙에서 발생하는 커스텀 예외 코드를 정의해요.
*/
public enum PaymentDomainExceptionCode {
}
/** DomainExceptionCode는 도메인 규칙에서 발생하는 커스텀 예외 코드를 정의해요. */
public enum PaymentDomainExceptionCode {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package depromeet.onepiece.payment.query.application;

/**
* 도메인 주도 개발 아키텍처에서 application 계층은 도메인 규칙에 핵심 로직 수행을 위임해요.
* 따라서 QueryService는 조회한 데이터를 DTO로 변환하거나, 여러 도메인 객체를 조합하여 응답 데이터를 만드는 역할을 합니다.
* 도메인 주도 개발 아키텍처에서 application 계층은 도메인 규칙에 핵심 로직 수행을 위임해요. 따라서 QueryService는 조회한 데이터를 DTO로 변환하거나,
* 여러 도메인 객체를 조합하여 응답 데이터를 만드는 역할을 합니다.
*/
public class PaymentQueryService {
}
public class PaymentQueryService {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package depromeet.onepiece.payment.query.application.exception;

/**
* QueryExceptionCode는 QueryService에서 발생하는 커스텀 예외 코드를 정의해요.
*/
public enum PaymentQueryExceptionCode {
}
/** QueryExceptionCode는 QueryService에서 발생하는 커스텀 예외 코드를 정의해요. */
public enum PaymentQueryExceptionCode {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package depromeet.onepiece.payment.query.domain;

/**
* 도메인 주도 개발 DDD 아키텍처에서는 조회 성능 향상을 위해 QueryRepository를 별도로 구현하여 CQRS 패턴을 적용합니다.
* Master-Slave 구조에서는 Master DB에 쓰기 작업을 하고, Slave DB에서 읽기 작업을 하기 때문에, QueryRepository를 별도로 구현해요.
* 도메인 주도 개발 DDD 아키텍처에서는 조회 성능 향상을 위해 QueryRepository를 별도로 구현하여 CQRS 패턴을 적용합니다. Master-Slave 구조에서는
* Master DB에 쓰기 작업을 하고, Slave DB에서 읽기 작업을 하기 때문에, QueryRepository를 별도로 구현해요.
*/
public interface PaymentQueryRepository {
}
public interface PaymentQueryRepository {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package depromeet.onepiece.payment.query.infrastructure;

/**
* RepositoryImpl은 Repository 인터페이스를 구현한 클래스로, 실제로 데이터베이스에 접근하여 데이터를 저장하거나 조회하는 역할을 해요.
* 데이터베이스 접근 기술(JPA DATA, QueryDSL, MyBatis 등)을 사용하여 구현합니다.
* 만약 JPA 및 QueryDSL을 사용한다면, infrastructure 패키지 내에 PaymentQueryJpaRepository, PaymentQueryQueryDslRepository 같이 구현 클래스를 생성할 수 있어요.
* RepositoryImpl은 Repository 인터페이스를 구현한 클래스로, 실제로 데이터베이스에 접근하여 데이터를 저장하거나 조회하는 역할을 해요. 데이터베이스 접근
* 기술(JPA DATA, QueryDSL, MyBatis 등)을 사용하여 구현합니다. 만약 JPA 및 QueryDSL을 사용한다면, infrastructure 패키지 내에
* PaymentQueryJpaRepository, PaymentQueryQueryDslRepository 같이 구현 클래스를 생성할 수 있어요.
*/
public class PaymentQueryRepositoryImpl {
}
public class PaymentQueryRepositoryImpl {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package depromeet.onepiece.payment.query.presentation;

/**
* 도메인 간 의존성을 제거하고 이벤트 소싱을 적용하기 위해 CQRS 패턴을 적용해요.
* CQRS 패턴은 명령(Command)과 조회(Query)를 분리하는 패턴으로, 이 중에서 조회(Query)는 상태를 조회하는 역할을 담당해요.
* Master-Slave 구조로 데이터베이스가 구성되어 있을 때, 조회 모델을 따로 분리하는 것이 조회 성능 향상에 도움이 될 수 있어요.
* 도메인 간 의존성을 제거하고 이벤트 소싱을 적용하기 위해 CQRS 패턴을 적용해요. CQRS 패턴은 명령(Command)과 조회(Query)를 분리하는 패턴으로, 이 중에서
* 조회(Query)는 상태를 조회하는 역할을 담당해요. Master-Slave 구조로 데이터베이스가 구성되어 있을 때, 조회 모델을 따로 분리하는 것이 조회 성능 향상에 도움이
* 될 수 있어요.
*/
public class PaymentQueryController {
}
public class PaymentQueryController {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@SpringBootTest
class OnepieceApplicationTests {

@Test
void contextLoads() {
}

@Test
void contextLoads() {}
}

0 comments on commit 7dd98d6

Please # to comment.