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

[Spring JDBC] 김이화 미션 제출합니다. #295

Merged
merged 8 commits into from
Jul 22, 2024

Conversation

ihwag719
Copy link

@ihwag719 ihwag719 commented Jul 7, 2024

mvc 리팩토링이랑 jdbc 한 번에 해서 올리게 되었습니다..

@ihwag719 ihwag719 changed the base branch from main to ihwag719 July 8, 2024 04:21
@sojeong0202
Copy link

간단하게 코멘트 남겼습니당~

Comment on lines 6 to 12
@Controller
public class WelcomeController {
@GetMapping("/")
public String welcome() {
return "index";
}
}

Choose a reason for hiding this comment

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

홈페이지 컨트롤러와 CR(U)D 컨트롤러를 따로 나눈 거 좋아보여요!

Choose a reason for hiding this comment

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

커스텀 예외처리 멋있어용👍👍

Comment on lines 15 to 16
public class ReservationController {
private AtomicLong index = new AtomicLong(1);

Choose a reason for hiding this comment

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

미션 요구 조건에 제거하라고 나와 있어서 제거하고 구현하는 게 좋을 것 같아요!

(혹시나 제가 요구 조건을 잘못 이해한 거라면 말씀해주세용~)

image

Copy link
Author

Choose a reason for hiding this comment

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

헉 지워서 제출하겠습니다

Comment on lines +35 to +42
public Reservation findReservationById(Long id) {
String sql = "SELECT id, name, date, time FROM reservation where id = ?";
try {
return jdbcTemplate.queryForObject(sql, rowMapper, id);
} catch (EmptyResultDataAccessException e) {
throw new NotFoundReservationException(id);
}
}

Choose a reason for hiding this comment

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

오 원래 DAO에 대해서 잘 알고 있었나요? 능숙해보여요

EmptyResultDataAccessException가 무슨 예외인지 궁금합니당

Copy link
Author

@ihwag719 ihwag719 Jul 10, 2024

Choose a reason for hiding this comment

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

아뇨 초록 스터디 학습테스트에서 열심히 해봤는데도 사용하는데 어려움이 많았습니다 ㅠㅠ
EmptyResultDataAccessException는 JDBC를 사용할 때 데이터베이스에서 조회 결과가 없을 경우 발생하는 예외라고 해서 사용했습니다!

Comment on lines +29 to +33
@GetMapping("/{id}")
@ResponseBody
public Reservation findReservationById(@PathVariable Long id) {
return reservationRepository.findReservationById(id);
}

Choose a reason for hiding this comment

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

여기에서는 왜 따로 ResponseEntity 활용을 안했는지 궁금합니당

Copy link
Author

Choose a reason for hiding this comment

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

ResponseEntity를 사용하지 않아도 예외가 발생하면 GlobalExceptionHandler에서 처리해줘서 크게 문제가 안 된다고 생각했습니다

Copy link

@bbggr1209 bbggr1209 left a comment

Choose a reason for hiding this comment

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

패키지 구분이 깔끔하게 잘 된 것 같아요!

Choose a reason for hiding this comment

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

Exception 명확하게 구분한 것 좋은 것 같아요!

}
}

public Reservation insert(Reservation reservation) {

Choose a reason for hiding this comment

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

@transactional에 대해서 공부해봐도 좋을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

@Transactional로 지정된 메소드가 호출될 때 트랜잭션이 시작되고, 메소드 실행이 끝나면 트랜잭션이 커밋되거나 롤백 됩니다.
트랜잭션 커밋은 트랜잭션 내의 모든 작업이 성공적으로 완료되어 데이터베이스에 영구적으로 반영되는 것을 의미하고 트랜잭션 롤백은 트랜잭션 내의 작업 중 하나라도 실패하거나 문제가 발생했을 때 트랜잭션이 시작된 이후의 모든 변경 사항을 취소하는 것을 의미합니다.
@Transactional은 데이터베이스 작업에서 원자성, 일관성, 고립성, 지속성. 즉, ACID 속성을 보장하기 위해 사용된다고 합니다!

Choose a reason for hiding this comment

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

RequestDto와 ResponseDto를 만들어 엔티티 분리하면 더 좋을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

[spring core]에 리팩토링 해서 만들었습니다!

if (reservation.getTime() == null || reservation.getTime().isEmpty()) {
throw new InvalidReservationException("time", "시간이 필요합니다.");
}
}

Choose a reason for hiding this comment

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

validateReservation 메소드 분리 할 수 있지 않을까요?! 중복된 코드를 줄이면 가독성이 좋아질 것 같아요

Copy link
Author

Choose a reason for hiding this comment

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

[spring core]에 리팩토링 해서 넣었습니다. 클래스로 나눠서 예외 처리 패키지에 넣었는데, 이걸 말씀하시는 게 맞을까요?

@boorownie boorownie merged commit bfab1bc into next-step:ihwag719 Jul 22, 2024
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.

5 participants