-
Notifications
You must be signed in to change notification settings - Fork 151
[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
base: yumyeonghan
Are you sure you want to change the base?
Conversation
src/test/java/com/programmers/jpa/item/domain/ItemRepositoryTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/programmers/jpa/item/domain/ItemRepositoryTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 남겼습니다~ 도진님이 리뷰를 잘 남겨주셔서 추가적인 리뷰는 없네요
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; | ||
} |
There was a problem hiding this comment.
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("고객이 존재하지 않습니다.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤 id가 들어왔는지 같이 표시해주면 좋을 것 같네요
There was a problem hiding this comment.
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("고객이 존재하지 않습니다.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 id 표시해주세요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반영했습니다!
2ba681b
📌 과제 설명
미션1 : 2. JPA 소개(단일 엔티티를 이용한 CRUD를 구현)
미션2 : 3. 영속성컨텍스트(customer 엔티티를 이용하여 생명주기 실습)
미션3 : 4-2. 연관관계매핑(order, order_item, item의 연관관계 매핑 실습)
👩💻 요구 사항과 구현 내용