Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[김영찬] 3차 과제 제출 #4

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

Conversation

hades3
Copy link
Member

@hades3 hades3 commented Nov 18, 2024

image

평소에 고민되던 부분 중 하나가 저는 Dto에서 엔티티로 변환할 때, 엔티티 클래스 내의 한 곳에서 정적 팩토리 메서드들을 오버로딩하여 생성하는 방법을 선택하고 있습니다. Dto에서 메서드를 선언하는 분들도 있는 것 같아서, 취향 차이인 것인지 특별히 좋은 이유가 있는 것인지 의견을 구하고 싶습니다.

Copy link
Member

@yooooonshine yooooonshine left a comment

Choose a reason for hiding this comment

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

LGTM~

@@ -19,6 +22,16 @@ public ResponseEntity<Object> handleApiException(ApiException e) {
return makeErrorResponseEntity(e.getHttpStatus(), e.getMessage(), e.getCode());
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Object> handleMethodArgumentNotValidException(MethodArgumentNotValidException e){
return makeErrorResponseEntity(HttpStatus.BAD_REQUEST, e.getBindingResult().getAllErrors().get(0).getDefaultMessage(), "POST-001");
Copy link
Member

Choose a reason for hiding this comment

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

ErrorCode를 사용하지 않고, 직접 POST-001 처럼 code를 명시한 전역 예외 핸들러를 구현하신 이유가 궁금합니다!


} catch (Exception e) {
log.error("Failed to save estates by excel", e);
throw ApiException.from(INTERNAL_SERVER_ERROR);
}
}

public FindPostResponse findPostById(Long id) {
Copy link
Member

Choose a reason for hiding this comment

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

읽기 전용이면 @Transactional(readOnly = true)를 붙여봐도 좋을 거 같아요.!

show_sql: true
format_sql: true
logging.level:
org.hibernate.SQL: debug
Copy link
Member

Choose a reason for hiding this comment

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

password를 빼 두신 걸 보니 보안을 고려해서 빼둔 거겠죠?
만약 h2 비번이 진짜 없는거면 이 부분은 git ignore 처리해주시면 좋을 거 같아요!


@Override
Page<Post> findAll(Pageable pageable);

Copy link
Member

Choose a reason for hiding this comment

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

이 코드에서 @Repository@Override를 명시하신 이유가 궁금합니다!

Copy link
Member

@u-genuine u-genuine left a comment

Choose a reason for hiding this comment

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

많이 배워갑니다 ㅎㅎ

}

@GetMapping("/list")
public ResponseEntity<?> findPosts(@PageableDefault(size = 10, sort = "views", direction = Sort.Direction.DESC)
Copy link
Member

Choose a reason for hiding this comment

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

@PageableDefault 어노테이션으로도 처리가 가능하네요 !! 배워갑니당

}

@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<Object> handleNoSuchElementException(NoSuchElementException e){
Copy link
Member

Choose a reason for hiding this comment

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

이런 예외가 존재하는지 몰랐는데 배워갑니다 👍


@Entity
@Getter
@Setter
Copy link
Member

Choose a reason for hiding this comment

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

무분별한 setter 사용은 지양하는게 좋다고 들었습니다!


private final JdbcTemplate jdbcTemplate;

public void saveAllByExcel(List<Post> posts) {
Copy link
Member

Choose a reason for hiding this comment

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

데이터베이스 저장 작업을 하기 때문에 Transactional 어노테이션을 고려하는 것도 좋을 거 같습니다!

Copy link
Member

@chanmin-00 chanmin-00 left a comment

Choose a reason for hiding this comment

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

깔끔한 코드 수고하셨습니다!

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.

4 participants