Skip to content

[4기 유명한] Springboot-jpa weekly 미션 1차 PR입니다. #306

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 57 commits into
base: yumyeonghan
Choose a base branch
from

Conversation

yumyeonghan
Copy link

📌 과제 설명

미션1 : 2. JPA 소개(단일 엔티티를 이용한 CRUD를 구현)
미션2 : 3. 영속성컨텍스트(customer 엔티티를 이용하여 생명주기 실습)
미션3 : 4-2. 연관관계매핑(order, order_item, item의 연관관계 매핑 실습)

👩‍💻 요구 사항과 구현 내용

  • 미션1: customer 엔티티를 만들어 CRUD를 구현했습니다.
  • 미션2: 영속성 컨텍스트 생명주기 실습을 테스트 환경에서 로그를 통해 진행했습니다.
  • 미션3: order, order_item, item의 연관관계 매핑을 실습하고, 테스트코드를 작성했습니다.

Copy link

@seung-hun-h seung-hun-h 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 50 to 62
public String getChef() {
if (!this.itemType.equals(FOOD)) {
throw new IllegalArgumentException("해당 상품은 음식이 아닙니다.");
}
return null;
}

public Long getPower() {
if (!this.itemType.equals(CAR)) {
throw new IllegalArgumentException("해당 상품은 자동차가 아닙니다.");
}
return null;
}

Choose a reason for hiding this comment

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

Item은 상품의 기본 정보만 담고 있고, 각 상품에 한정적인 부분은 추상 클래스에 포함할 필요는 없을 것 같아요.
특정 상품의 타입을 명시적으로 알아야 하는 경우라면 Item이 아닌 Car, Food 같은 특정 타입으로 사용하면 될 것 같아요.
그리고 Spring Data Jpa에서도 이런 상속 구조를 위해서 제네릭을 제공하는 것으로 보이네요

public interface ItemRepository<T extends Item> extends JpaRepository<T, Long> {
}

특정 상품의 타입을 명시적으로 알아야 하는 경우 라고 하면 getChef를 반드시 호출해야 하는 경우라고 볼 수 있을 것 같네요.

public FindResponse findById(Long id) {
return customerRepository.findById(id)
.map(FindResponse::from)
.orElseThrow(() -> new IllegalArgumentException("고객이 존재하지 않습니다."));

Choose a reason for hiding this comment

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

어떤 id가 들어왔는지 같이 표시해주면 좋을 것 같네요

Copy link
Author

Choose a reason for hiding this comment

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

반영했습니다!

@Transactional
public Long update(UpdateRequest updateRequest) {
Customer foundCustomer = customerRepository.findById(updateRequest.id())
.orElseThrow(() -> new IllegalArgumentException("고객이 존재하지 않습니다."));

Choose a reason for hiding this comment

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

여기도 id 표시해주세요

Copy link
Author

Choose a reason for hiding this comment

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

반영했습니다!
2ba681b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants