Skip to content

[4기 나영경] Springboot-jpa weekly 미션 1차 PR입니다. #323

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 83 commits into
base: na-yk
Choose a base branch
from

Conversation

na-yk
Copy link

@na-yk na-yk commented Aug 3, 2023

📌 과제 설명

  • 미션1 : 2. JPA 소개(단일 엔티티를 이용한 CRUD를 구현)
  • 미션3 : 4-2. 연관관계매핑(order, order_item, item의 연관관계 매핑 실습)

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

  • 스프링 프로젝트의 전반적인 사항을 공부하고자 미션 요구 사항 외 구현한 부분들이 있습니다.
  • Customer 엔티티로 미션1을 수행하였고, 추후 Order, Product, User 엔티티로 미션3을 수행했습니다.
  • orderId, productId, quantity로 구성된 OrderProduct 엔티티를 추가하여 Order 생성 시 주문한 제품과 그 수를 저장할 수 있도록 했습니다.
  • 생성(create) 외 동작들도 구현할 예정입니다.

✅ PR 포인트 & 궁금한 점

  • createOrder을 할 때 관련 OrderProduct를 생성하는데, save()를 반복 호출하는 것이 좋지 않다고 생각해서 saveAll()을 이용해보았습니다. 적절한 사용인지 궁금합니다!

wisehero and others added 30 commits May 9, 2022 15:29
@na-yk na-yk requested review from seung-hun-h and dojinyou August 3, 2023 05:44
@na-yk na-yk self-assigned this Aug 3, 2023
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 21 to 29
@Builder
public Customer(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public static CustomerResponse from(Customer customer){
return new CustomerResponse(customer.getFirstName(), customer.getLastName());
}

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.

이건 별다른 이유는 없고, 페어프로그래밍을 하면서 각각을 사용해보는 연습을 하고 남겨둔 것이었습니다. 불필요한 부분은 삭제했습니다!

.build();
orderProducts.add(orderProduct);
});
orderProductRepository.saveAll(orderProducts);

Choose a reason for hiding this comment

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

save를 한 번씩 호출하는 것보다 saveAll을 호출해주는 것이 더 좋은 것 같아요.
ID 생성 타입이 IDENTITY인 경우에는 bulk insert가 안된다고하니 참고하셔도 좋을 것 같습니다.
테스트 코드를 작성해서 쿼리가 어떻게 생성되는지 확인해보면 좋을 것 같아요

https://github.com/prgrms-be-devcourse/springboot-jpa/pull/305/files/1dcfec1b48c84e8b8111640730f7f84c15406d7e#r1278570133

Comment on lines 18 to 19

public Long createUser(UserCreateRequest request){

Choose a reason for hiding this comment

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

Suggested change
public Long createUser(UserCreateRequest request){
@Transactional
public Long createUser(UserCreateRequest request){

Choose a reason for hiding this comment

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

제거해주세요~

}

@PostMapping
public ResponseEntity<Long> customerCreate(@RequestBody CustomerRequest request) {

Choose a reason for hiding this comment

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

이렇게하면 파라미터 validation이 이루어지나요?

import org.springframework.data.jpa.repository.JpaRepository;

public interface CustomerRepository extends JpaRepository<Customer, Long> {
String findByFirstName(String firstName);

Choose a reason for hiding this comment

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

이건 왜 String을 반환하나요?

Copy link
Member

@dojinyou dojinyou left a comment

Choose a reason for hiding this comment

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

고생하셨습니다.

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.

8 participants