[Spring Core] 이준민 미션 제출합니다 :)#384
Conversation
7589a0a to
45d4f6c
Compare
TaeyeonRoyce
left a comment
There was a problem hiding this comment.
안녕하세요, 준민님
계층별로 잘 나누어 수정하신 것 같지만, 한가지 아쉬운 부분이 있어 코멘트 남겨두었습니다.
별다른 질문이 없으셔서 코드 위주로만 리뷰 남겼어요.
고생하셨어요~
|
|
||
| return ResponseEntity.created(URI.create("/reservations/" + id)).body(newReservation); | ||
| Reservation newReservation = reservationService.addReservation(request); | ||
| return ResponseEntity.created(URI.create("/reservations/" + newReservation.getId())).body(newReservation); |
There was a problem hiding this comment.
괄호가 깊게 중첩되어 있어요.
풀어내면 가독성이 좋아질 것 같아요
| @Repository | ||
| public class ReservationDao { |
There was a problem hiding this comment.
어노테이션은 Repository를,
클래스는 Dao라는 네이밍을 사용하셨군요.
둘의 차이가 어떤것이라 생각하시고, Dao라는 네이밍을 적용하신 이유가 궁금해요
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { |
| public void validateAndSetTimeId(JdbcTemplate jdbcTemplate) { | ||
| if (name == null || name.isEmpty() || date == null || date.isEmpty() || time == null || time.isEmpty()) { | ||
| throw new InvalidReservationException("필수 입력값이 누락되었습니다."); | ||
| } | ||
|
|
||
| try { | ||
| timeId = Long.parseLong(time); | ||
| } catch (NumberFormatException e) { | ||
| throw new InvalidReservationException("유효하지 않은 timeId입니다: " + time); | ||
| } | ||
|
|
||
| String timeQuery = "SELECT time FROM time WHERE id = ?"; | ||
| try { | ||
| // timeId로 유효성 검사 | ||
| String resolvedTime = jdbcTemplate.queryForObject(timeQuery, String.class, timeId); | ||
| if (resolvedTime == null) { | ||
| throw new InvalidReservationException("유효하지 않은 timeId입니다: " + timeId); | ||
| } | ||
| } catch (EmptyResultDataAccessException e) { | ||
| throw new InvalidReservationException("유효하지 않은 시간입니다: " + timeId); | ||
| } |
There was a problem hiding this comment.
이 코드는 문제가 많아보이네요.
레이어드 아키텍쳐를 활용하여 각 계층별 관심사를 분리하였는데, ReservationRequest(presentation)에서 jdbcTemplate을 의존하는 것은 수정해야 할 것 같아요.
요청에 대한 모든 검증이 이곳에서 이루어 지고 있는것이 문제인데요.
요청에 대한 검증을 단계별로 나누어 계층에 맞게 배치시키면 어떨까요?
- null 값 검증
- 포맷 검증
- 존재하는 자원인지에 대한 검증 (DB 의존)
각 검증을 적절한 계층에서 이루어지도록 나눠주세요.
| return time; | ||
| } | ||
|
|
||
| public void setTime(String time) { |
There was a problem hiding this comment.
전체적으로 객체 내의 setter는 제거해주세요
현재 setTime은 사용 하지 않는 것 같아요.
| } | ||
|
|
||
| public Time addTime(Time time) { | ||
| if (time.getTime() == null || time.getTime().trim().isEmpty()) { |
There was a problem hiding this comment.
값에 대한 단순 검증은 어디에서 이루어지면 좋을까요?
꼭 service 영역에서 해야하는걸까요?
추가로 time.getTime().trim().isEmpty()은 time.getTime().isBlank()로 제공 되는 기능이 있습니다
| time_id BIGINT, | ||
| PRIMARY KEY (id), | ||
| FOREIGN KEY (time_id) REFERENCES time(id) | ||
| ); No newline at end of file |
No description provided.