-
Notifications
You must be signed in to change notification settings - Fork 3
Convention
harper edited this page Nov 1, 2024
·
1 revision
GitHub - google/styleguide: Style guides for Google-originated open-source projects
-
branch des main 배포용 브랜치 dev 개발 머지용 브랜치 feature 기능 개발용 브랜치 hotfix 버그 처리 브랜치 feat(#22): 로그인 API 구현 - 개발사항 작성
- 멀티모듈로 도메인을 분리해서 관리
- 모노레포로 코드관리
project ├── common # 공통 모듈 │ └── domain │ ├── service │ ├── dto # 외부서비스 통신을 위한 dto 모듈 │ │ └── OrderDTO.java │ ├── server # 서비스 서버 모듈 │ │ ├── service │ │ │ └── OrderService.java │ │ ├── domain │ │ │ ├── model │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ └── service │ │ │ └── OrderDomainService.java │ │ ├── infrastructure │ │ │ ├── repository │ │ │ ├── configuration │ │ │ └── messaging │ │ │ └── KafkaMessageProducer.java │ │ └── presentation │ │ ├── controller │ │ └── request
- addProduct
- getProduct
- getProductList
- deleteProduct
- updateProduct
@Getter @RequiredArgsConstructor public enum ProductErrorCode { private final HttpStatus status; private final String message; }
각 서비스마다 에러코드 관리
@Getter public abstract class BusinessException extends RuntimeException { protected String statusName; private final String message; public BusinessException(String statusName, String message) { super(message); this.statusName = statusName; this.message = message; } public BusinessException(String statusName, String message, Object... args) { super(formattingErrorMessage(message, args)); this.statusName = statusName; this.message = formattingErrorMessage(message, args); } private static String formattingErrorMessage(String message, Object... objects) { return message.formatted(objects); } }
공통모듈에서 커스텀예외 클래스 관리
public class ProductException extends BusinessException { private final ProductErrorCode errorCode; public ProductException(ProductErrorCode errorCode, Object... args) { super(errorCode.getStatus(), errorCode.getMessage(), args); } }
공통모듈에서 상속받아 각 서비스별 예외 클래스 정의
커스텀예외 예시
@Getter public enum ProductErrorCode { NOT_EXIST(NOT_FOUND, "요청에 해당하는 상품이 존재하지 않습니다. : [%s]"); private final HttpStatus status; private final String message; ProductErrorCode(HttpStatus status, String message) { this.status = status; this.message = message; } }
Product product = productRepository.findById(UUID.fromString(productId)) .orElseThrow(() -> new ProductException(ProductErrorCode.NOT_EXIST, productId));
@MappedSuperclass @EntityListeners(AuditingEntityListener.class) @Getter public abstract class BaseEntity { @CreatedDate private LocalDateTime createdAt; @CreatedBy private String createdBy; @LastModifiedDate private LocalDateTime updatedAt; @LastModifiedBy private String updatedBy; }
감사관련 필드 공통모듈에서 관리
@Getter @NoArgsConstructor public class ApiResponse<T> { private String statusName; private String message; private T data; private ApiResponse(String statusName, String message, T data) { this.statusName = statusName; this.message = message; this.data = data; } public static ApiResponse<Void> error(String statusName, String message) { return new ApiResponse<>(statusName, message, null); } public static <T> ApiResponse<T> error(String statusName, String message, T data) { return new ApiResponse<>(statusName, message, data); } public static <T> ApiResponse<T> created(T data) { return new ApiResponse<>("CREATED", null, data); } public static <T> ApiResponse<T> ok(T data) { return new ApiResponse<>("OK", null, data); } }
공통모듈에서 공통응답객체 관리
### Code Convention## 🎯 What is this PR
- 코드 변경 사유 및 목적 설명 (개요)
📄 Changes Made
- 구현 내용 설명
🙋🏻 Review Point
- 리뷰어가 확인해야 할 사항 코멘트
✅ Test
- 완료한 테스트 항목 > 스크린 샷 첨부
🔗 Reference
Issue #{이슈번호}
[GitHub - google/google-java-format: Reformats Java source code to comply with Google Java Style.](https://github.com/google/google-java-format)
[GitHub - google/styleguide: Style guides for Google-originated open-source projects](https://github.com/google/styleguide)
-
GitLab Flow
branch des main 배포용 브랜치 dev 개발 머지용 브랜치 feature 기능 개발용 브랜치 hotfix 버그 처리 브랜치 -
신규 기능 개발 브랜치 생성 시 반드시 dev에서 진행
-
dev 에 머지 후 featrue 브랜치 제거
-
feat/2-OrderAPI (feat/이슈번호-브랜치이름)
Tag name Description feat 새로운 기능을 추가 refactor 코드 리팩토링 (성능의 변화는 없음) enhance 성능 개선 fix 버그 수정 style 코드 포맷 변경, 세미 콜론 누락, 코드 수정이 없는 경우 comment 필요한 주석 추가 및 변경 docs 문서 수정 test 테스트 코드, 리펙토링 테스트 코드 추가, Production Code(실제로 사용하는 코드) 변경 없음 chore 빌드 업무 수정, 패키지 매니저 수정, 패키지 관리자 구성 등 업데이트, Production Code 변경 없음 rename 파일 혹은 폴더명을 수정하거나 옮기는 작업만인 경우 delete 파일을 삭제하는 작업만 수행한 경우 feat(#22): 로그인 API 구현 - 개발사항 작성
## 🎯 What is this PR - 코드 변경 사유 및 목적 설명 (개요) ## 📄 Changes Made - 구현 내용 설명 ## 🙋🏻 Review Point - 리뷰어가 확인해야 할 사항 코멘트 ## ✅ Test - [ ] 완료한 테스트 항목 > 스크린 샷 첨부 ## 🔗 Reference Issue #{이슈번호}