Skip to content

Conversation

@DFDRDODM95
Copy link
Contributor

No description provided.

DFDRDODM95 added 10 commits May 1, 2024 14:57
    * API 스펙 유지를 위하여 exception 클래스 필드 추가
        * exception 발생 시 data 전달을 위한 Json Mapper 추가
            * 적용을 위한 DTO 클래스 변경
    * exception handler 클래스들이 복수 개 존재하여 필요사항 설정
        * Priority와 basePackages 설정
    * 서비스 코드 exception 사용으로 인한 변경
    * json 변환 용도의 string을 전달하는 게 아니라
    * ReviewDto 공통 인터페이스를 그대로 전달하는 형식으로 변경
    * 클래스 단위가 아닌 생성자 Builder 사용으로 보호 수준 확보
    * Response DTO 작성과 그에 따른 변경
Comment on lines +19 to +21
@Data // TODO : data 어노테이션의 위험성 상 제거하는 게 좋을 듯함
@SuperBuilder(builderMethodName = "superBuilder")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Copy link
Contributor Author

@DFDRDODM95 DFDRDODM95 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data 어노테이션의 위험성을 경계해서 우선 주석으로 남겨 놓았고
실무에서 Lombok 사용법

builder의 이름 중복 문제는 SuperBuilder의 것을 변경하도록 했습니다.

또한 기본 생성자 어노테이션의 접근 범위를 지정하여 보호 수준을 만들었습니다.

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"),
;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorCode 관련 작업은 이전에 진행한 것으로 변경 가능성이 남아있는 상태입니다.

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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builder를 클래스 단위가 아닌 생성자 단위로 모두 변경하였고
Assert문을 메서드 본문과 같이 작성함으로써 더 안전하게 쓸 수 있다고 합니다.

Comment on lines +49 to +65
@BeforeEach
void setUp() {
hospital = createHospital("병원1", "000-0000-0001");
parent = createParent("testSignUp1", "010-0000-0001", "0000000000000", "[email protected]");
}

// 메서드 시그너쳐 상 동일성 비교가 불가능하므로 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());
}
Copy link
Contributor Author

@DFDRDODM95 DFDRDODM95 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 메서드에서는 이런 식으로 주석문을 같이 적어 놓았습니다.

주로 참고한 글

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO에 해당하는 작업입니다.

리포지토리 테스트 메서드가
서비스 계층 테스트의 동일성 확인을 보장해주는 것과 같이
POJO 메서드들이 작동하지 않으면 실패하기 때문에

toDto, fromEntity등의 코드를 작성해주는 것이 좋다고 생각합니다.

@sinsj5858 sinsj5858 marked this pull request as ready for review June 12, 2024 11:40
@DFDRDODM95
Copy link
Contributor Author

DFDRDODM95 commented Jun 12, 2024

원준님께서 draft request 기능 확인 도와주셨습니다.
작업하고 있을게요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants