Skip to content

[Spring MVC] 홍석주 미션 제출합니다. #415

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

Open
wants to merge 9 commits into
base: somefood
Choose a base branch
from

Conversation

somefood
Copy link

안녕하세요 석환님,

3주차 과제 제출드리오니 시간 괜찮으실 때 확인 부탁드립니다!
감사합니다 ㅎㅎ

Copy link

@seokhwan-an seokhwan-an left a comment

Choose a reason for hiding this comment

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

석주님 미션 구현해주시느라 고생하셨습니다.
리뷰 남겼는데 천천히 봐주세요!

Comment on lines 41 to 49
String sql = "SELECT " +
"r.id as reservation_id," +
"r.name," +
"r.date," +
"t.id as time_id," +
"t.time as time_value " +
"FROM reservation r " +
"INNER JOIN reservation_time t ON r.time_id = t.id " +
"WHERE r.id = ?";

Choose a reason for hiding this comment

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

조인을 이용해서 reservation을 조회할 때 time 정보까지 한번에 불러오는 것 좋네요!

Comment on lines +14 to +15
@RestController
public class TimeCommandController {

Choose a reason for hiding this comment

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

@RequestMapping을 활용해서 url의 공통적인 부분을 추출해보는 것도 좋을 것 같아요
저는 @RequestMapping을 활용하면 개인적으로 한 눈에 요청 주체를 파악하기 쉬어서 @RequestMapping을 이용하는 것을 선호합니다.

Choose a reason for hiding this comment

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

더불어 현재 시간 관리 페이지로 응답해주는 처리 담당이 없는 것 같습니다. 이 부분 추가해 주세요!

Copy link
Author

Choose a reason for hiding this comment

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

@RequestMapping을 활용해서 url의 공통적인 부분을 추출해보는 것도 좋을 것 같아요 저는 @RequestMapping을 활용하면 개인적으로 한 눈에 요청 주체를 파악하기 쉬어서 @RequestMapping을 이용하는 것을 선호합니다.

저는 회사의 코드 영향 때문일 수도 있는데, 회사에서 석환님 방식대로 컨트롤러 상단 @RequestMapping에 공통적인 부분을 두어져 있는게 더러 있습니다.
근데 이것이 개인적으로 IDE에서 검색하기 힘들어져서 저는 각 Mapping에 full url 두는 방법을 좀 더 선호하게 되었습니다 ㅎㅎ
물론 /api 등의 공통된 접두사가 붙게되거나 하면 공통적인 부분을 추출하는것도 좋다 생각하지만, 현재 제 생각은 그렇습니다~!

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 25 to 26
return timeDao.findById(id)
.orElseThrow();

Choose a reason for hiding this comment

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

혹시 존재하지 않는 시간대를 조회하는 경우에 아무런 예외를 발생시키지 않는 이유는 무엇인가요?

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 41 to 49
String sql = "SELECT " +
"r.id as reservation_id," +
"r.name," +
"r.date," +
"t.id as time_id," +
"t.time as time_value " +
"FROM reservation r " +
"INNER JOIN reservation_time t ON r.time_id = t.id " +
"WHERE r.id = ?";

Choose a reason for hiding this comment

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

Suggested change
String sql = "SELECT " +
"r.id as reservation_id," +
"r.name," +
"r.date," +
"t.id as time_id," +
"t.time as time_value " +
"FROM reservation r " +
"INNER JOIN reservation_time t ON r.time_id = t.id " +
"WHERE r.id = ?";
String sql = """
SELECT
r.id AS reservation_id,
r.name,
r.date,
t.id AS time_id,
t.time AS time_value
FROM reservation r
INNER JOIN reservation_time t ON r.time_id = t.id
WHERE r.id = ?
""";

아래와 같이 관리하면 불필요한 + 단어를 제거할 수 있어 조금 더 가독성이 좋을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

하도 자바 8만 쓰다보니 멀티라인의 존재를 자꾸 잊게 되네요 ㅎㅎ
리마인드 감사드립니다! ㅎㅎ

Comment on lines 34 to 47
@PostMapping("/times")
public ResponseEntity<TimeCreateResponse> createTime(@RequestBody TimeCreateRequest request) throws URISyntaxException {
Time time = timeDao.save(Time.ofNew(
request.getTime()
));

URI uri = new URI("/times/" + time.getId());
return ResponseEntity
.created(uri)
.body(new TimeCreateResponse(
time.getId(),
time.getTime()
));
}

Choose a reason for hiding this comment

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

해당 요청은 같은 시간을 중복해서 저장할 수 있을 것 같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

오 맞네요
해당 부분도 처리했습니다~! ㅎㅎ

}, keyHolder);

return Time.ofExist(
Objects.requireNonNull(keyHolder.getKey()).longValue(),

Choose a reason for hiding this comment

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

Objects.requireNonNull을 이용하신 이유는 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

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

단순히 IDE에서 경고로 잡아줘서 사용한겁니다 ㅎㅎ
null 인경우 똑같이 NullPointerException을 던져줄테지만, 사전에 NonNull임을 명시해줌으로써 안정성을 높일 수 있지 않을까 생각됩니다~!

Comment on lines 29 to 46
@GetMapping("/times")
public List<Time> getTimes() {
return timeDao.findAll();
}

@PostMapping("/times")
public ResponseEntity<TimeCreateResponse> createTime(@RequestBody TimeCreateRequest request) throws URISyntaxException {
Time time = timeDao.save(Time.ofNew(
request.getTime()
));

URI uri = new URI("/times/" + time.getId());
return ResponseEntity
.created(uri)
.body(new TimeCreateResponse(
time.getId(),
time.getTime()
));

Choose a reason for hiding this comment

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

Time 객체를 반환하는 요청과 TimeCreateResponse 객체로 반환하는 요청의 차이가 있을까요? 현재 Time 객체와 TimeCreateResponse 객체 간의 차이가 없다고 느껴지는데 분리하신 이유는 무엇인가요?

Choose a reason for hiding this comment

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

더불어서 dto를 이용하는 이유는 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

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

네 저번 1주차에도 해주셨던 질문 같은데요, 저번처럼 validation 목적으로 DTO를 만든 것도 있습니다. (아직은 안 쓰지만? ㅎㅎ)
지금은 단순한 컨트롤러이지만 추가 요구 사항이 발생해서 여러 객체와 협업해야하는 상황에서 Time 객체로 입력을 받으면 추후 유연성이 떨어질 것을 고려하기에 여러 값을 받을 수 있는 DTO로 구성하고, 해당 객체로 비즈니스 로직에서 다양하게 활용할 수 있게 하기 위해서 사용 했습니다~!

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.

2 participants