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 Core] 안정현 미션 제출합니다. #272

Open
wants to merge 21 commits into
base: anhye0n
Choose a base branch
from

Conversation

Anhye0n
Copy link

@Anhye0n Anhye0n commented May 27, 2024

Core 미션!

안녕하세요! 명수님 이번주도 고생 많으셨습니다!

이번 과제에서는

  • 과제 피드백으로 배웠던 LocalTime 타입으로 형식 변경하기
  • NamedParameterJdbcTemplate로 변경
  • controller -> service -> dao 순서 계층화
    를 주로 진행하였습니다.

계층화를 진행하며, 제가 작성한 코드에서는 service의 역할이 너무 작았기에, 이런 계층화도 좋은 계층화라 볼 수 있을까..? 하는 생각이 많이 들었습니다.

저의 계층화에서 부족한 부분이 무엇이라 생각하시는지, 제가 작성한 service가 옳은 건지..에 대해서 피드백 주신다면 감사하겠습니다!

마지막 커밋 부분에 10단계 완료라고 써놓는걸 깜빡하고 push를 했습니다.. 참고 부탁드립니다!

Copy link

@mangsuyo mangsuyo left a comment

Choose a reason for hiding this comment

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

안녕하세요 정현님.
미션 수행하느라 고생하셨습니다 👍

전체적으로 코드를 읽기 수월하였고 계층대로 역할과 책임을 잘 구분하신 것 같습니다!

저희 미션이 데이터 접근 기능이 대부분이다 보니 Service계층에서 주로 저장소에 접근 및 반환만 하기 때문에 저도 비슷한 고민을 한 것 같아요!

그러나 이러한 상황에서도 저는 따로 Service 계층을 두는 것을 선호하는데요.
이후의 요구사항 변화에 대응하기 유리하고 코드의 역할과 책임을 분리했을 때 유지보수가 쉽다는 점 때문입니다!

편하게 리뷰 답변 달아주시고 더 이야기 하고 싶으신 점도 말씀 해주세요 :)

Comment on lines +6 to +20
@Controller
public class AppController {

@GetMapping("/")
public String viewHome() {

return "home";
}

@GetMapping("/reservation")
public String viewReservation(){

return "new-reservation";
}
}
Copy link

@mangsuyo mangsuyo May 28, 2024

Choose a reason for hiding this comment

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

time.html을 반환해서 기능들이 잘 작동하는지 페이지에서 시각적으로 확인해보셔도 좋을 것 같습니다!

Comment on lines +13 to +15
@Controller
public class ReservationController {
private ReservationService reservationService;

Choose a reason for hiding this comment

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

혹시 reservationService가 정상적으로 주입되나요?

스프링에서 의존성 주입의 원리를 저에게 알려주세요 :)

Comment on lines +27 to +28
@DateTimeFormat(pattern = "HH:mm")
@RequestBody Time time

Choose a reason for hiding this comment

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

@DateTimeFormat@RequestBody에서 동작하지 않는다고 하네요 :)

@DateTimeFormat을 이용한 날짜 포매팅

Comment on lines +17 to +24
private final JdbcTemplate jdbcTemplate;

@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

public ReservationRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

Choose a reason for hiding this comment

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

의존성을 주입받을 때 필드 주입 방식과 생성자 주입 방식 두 가지를 사용하셨군요!

두 방식을 한 클래스 안에서 사용하신 이유와 장단점을 저에게 알려주세요 :)

Comment on lines +7 to +9

public class ReservationService {

Copy link

@mangsuyo mangsuyo May 28, 2024

Choose a reason for hiding this comment

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

Service 어노테이션이 빠졌네요!

이러한 어노테이션은 의존성 주입에 관련해서 어떤 기능을 하는지 저에게 알려주세요 :)

return timeRepository.findAll();
}

public Time inserTime(Time time) {

Choose a reason for hiding this comment

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

오타가 있네요!

Comment on lines +17 to +24
public Reservation(String name, String date, Time time) {
validateEmpty(name);
validateDate(date);

this.name = name;
this.date = date;
this.time = time;
}

Choose a reason for hiding this comment

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

클라이언트에서 시간관리 페이지 에서 등록된 시간을 예약관리 페이지에서 선택하면 Time 객체가 아닌 해당 시간의 id를 전달합니다.

다음은 클라이언트에서 /reservation의 Post 요청 json입니다.
{ "date": "2023-08-05", "name": "브라운", "time": 1 }

따라서 이후에 time_id에 맞는 time 객체를 데이터베이스를 이용하여 찾아주시고 Reservation에 반영해주시면 될 것 같습니다!

또한 ReservationTime에 의존하기 시작한 이후로 요청과 응답의 형태가 변화하게 되었는데 DTO를 통해서 이러한 변경에 대한 부담과 검증에 대한 부담을 나눠가져도 좋을 것 같아요.

혹시 정현님은 DTO를 분리하시지 않은 이유가 있을까요?

Comment on lines +26 to +34
public Reservation(int id, String name, String date, Time time) {
validateEmpty(name);
validateDate(date);

this.id = id;
this.name = name;
this.date = date;
this.time = time;
}

Choose a reason for hiding this comment

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

DB에서 가져온 값인 namedate를 다시 validate 하시는 이유가 궁금합니다 :)

Comment on lines +48 to +50
public void setName(String name) {
this.name = name;
}

Choose a reason for hiding this comment

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

정현님의 코드에서 setter 를 사용하고 있지 않고 있습니다!
사용하지 않는 메서드는 제거해도 좋을 것 같습니다 :)

또한 저는 setter를 사용하는 것을 지양하는 편인데요.
정보를 담고 있는 도메인의 필드를 어디에서나 setter를 통해 값을 변경할 수 있다면 일관성을 깨뜨리고, 유지보수의 어려움 등 많은 문제를 야기하게 됩니다!

세터를 지양해야 하는 이유를 담은 좋은 글이 있어서 소개해드립니다 :)
세터 사용을 지양해야 하는 이유


@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public class TimeTest {

Choose a reason for hiding this comment

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

현재 테스트가 통과 되고 있지 않습니다.

  • 의존성 문제 해결
  • 9단계 요구사항

위의 두 가지를 해결하시면 모두 통과될 것 같습니다!

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