Open
Conversation
* API 스펙 유지를 위하여 exception 클래스 필드 추가
* exception 발생 시 data 전달을 위한 Json Mapper 추가
* 적용을 위한 DTO 클래스 변경
* exception handler 클래스들이 복수 개 존재하여 필요사항 설정
* Priority와 basePackages 설정
* 서비스 코드 exception 사용으로 인한 변경
* json 변환 용도의 string을 전달하는 게 아니라
* ReviewDto 공통 인터페이스를 그대로 전달하는 형식으로 변경
* 클래스 단위가 아닌 생성자 Builder 사용으로 보호 수준 확보
* Response DTO 작성과 그에 따른 변경
DFDRDODM95
commented
Jun 11, 2024
Comment on lines
+19
to
+21
| @Data // TODO : data 어노테이션의 위험성 상 제거하는 게 좋을 듯함 | ||
| @SuperBuilder(builderMethodName = "superBuilder") | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) |
Contributor
Author
There was a problem hiding this comment.
Data 어노테이션의 위험성을 경계해서 우선 주석으로 남겨 놓았고
실무에서 Lombok 사용법
builder의 이름 중복 문제는 SuperBuilder의 것을 변경하도록 했습니다.
또한 기본 생성자 어노테이션의 접근 범위를 지정하여 보호 수준을 만들었습니다.
DFDRDODM95
commented
Jun 11, 2024
Comment on lines
+8
to
+14
| @AllArgsConstructor | ||
| @Getter | ||
| public enum ReviewErrorCode implements ErrorCode { | ||
| Review_Not_Found(HttpStatus.NOT_FOUND, "No Review"), | ||
| Hospital_Not_Found(HttpStatus.NOT_FOUND, "No Hospital"), | ||
| Parent_Not_Found(HttpStatus.NOT_FOUND, "No Parent"), | ||
| ; |
Contributor
Author
There was a problem hiding this comment.
ErrorCode 관련 작업은 이전에 진행한 것으로 변경 가능성이 남아있는 상태입니다.
DFDRDODM95
commented
Jun 11, 2024
Comment on lines
+34
to
+45
| @Builder | ||
| public ReviewCreateRequest(String title, Integer score, String description, Long hospitalId, Long parentId) { | ||
| Assert.hasText(title, "title must not be empty"); | ||
| Assert.notNull(score, "score must not be null"); | ||
| Assert.notNull(hospitalId, "hospitalId must not be null"); | ||
| Assert.notNull(parentId, "parentId must not be null"); | ||
| this.title = title; | ||
| this.score = score; | ||
| this.description = description; | ||
| this.hospitalId = hospitalId; | ||
| this.parentId = parentId; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
builder를 클래스 단위가 아닌 생성자 단위로 모두 변경하였고
Assert문을 메서드 본문과 같이 작성함으로써 더 안전하게 쓸 수 있다고 합니다.
DFDRDODM95
commented
Jun 11, 2024
Comment on lines
+49
to
+65
| @BeforeEach | ||
| void setUp() { | ||
| hospital = createHospital("병원1", "000-0000-0001"); | ||
| parent = createParent("testSignUp1", "010-0000-0001", "0000000000000", "testSignUp@naver.com"); | ||
| } | ||
|
|
||
| // 메서드 시그너쳐 상 동일성 비교가 불가능하므로 repository 테스트로 이를 대체하고 반환값만 검증하였음 | ||
| // 테스트 DB가 계속 비어있다는 가정이면, 전체 조회를 2회 시행해서 전후를 비교하고 괜찮은 보호 수준을 확보해도 문제 없을 것. | ||
| @Test | ||
| @DisplayName("리뷰 생성에 성공한다.") | ||
| void createReview_positiveCase() { | ||
| ReviewCreateRequest request = createReviewCreateRequest("리뷰 1", hospital, parent); | ||
|
|
||
| Api<ReviewCreateResponse> apiResponse = reviewService.createReview(request); | ||
|
|
||
| assertThat(apiResponse.getData().getTitle()).isEqualTo(request.getTitle()); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
테스트 메서드에서는 이런 식으로 주석문을 같이 적어 놓았습니다.
DFDRDODM95
commented
Jun 11, 2024
Comment on lines
+51
to
+59
| // ToDto, fromEntity 등 POJO 메서드들에 대한 테스트 추가해야 함 | ||
| // 메서드는 객체 간 협력을 검사하는 역할만 수행하고 있다. | ||
| @Test | ||
| void 리뷰_생성에_성공한다() { | ||
| doReturn(1L).when(hospital).getId(); | ||
| doReturn(1L).when(parent).getId(); | ||
| Mockito.when(hospitalRepository.findById(any(Long.class))).thenReturn(Optional.ofNullable(hospital)); | ||
| Mockito.when(parentRepository.findById(any(Long.class))).thenReturn(Optional.ofNullable(parent)); | ||
| ReviewCreateRequest request = createReviewCreateRequest("리뷰 1", hospital, parent); |
Contributor
Author
There was a problem hiding this comment.
TODO에 해당하는 작업입니다.
리포지토리 테스트 메서드가
서비스 계층 테스트의 동일성 확인을 보장해주는 것과 같이
POJO 메서드들이 작동하지 않으면 실패하기 때문에
toDto, fromEntity등의 코드를 작성해주는 것이 좋다고 생각합니다.
sinsj5858
approved these changes
Jun 12, 2024
Contributor
Author
|
원준님께서 draft request 기능 확인 도와주셨습니다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.