-
Notifications
You must be signed in to change notification settings - Fork 152
[4기] 유원우,안재영 Mission 1(단일 엔티티 CRUD),3(연관관계 매핑) 과제 제출합니다. #315
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: 원우,재영_mission3
Are you sure you want to change the base?
Conversation
- SpringBoot 프로젝트 생성 - .gitignore 초기화
id 'io.spring.dependency-management' version '1.1.2' | ||
} | ||
|
||
group = 'org.wonu606' |
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.
group 이름은
일반적으로 작성하는 회사의 도메인 명을 거꾸로 사용해요
ex) naver.com -> group = com.naver
네이밍 룰은 Package 네이밍 룰을 따르고 하위 값을 추가할 수 있는데, 보통 프로젝트 이름을 쓰곤 합니다.
com.wncompany.shop
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-devtools:3.1.1' |
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.
devtools를 사용하시는 이유가 있으신가요?
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.
Devtool를 사용하면 웹 테스트할 때 편하다는 것을 알게 되어 적용하였습니다.
한데, 현재 웹을 구현하지 않아 사용하고 있지 않습니다.
의존성은 좋다고 볼 때 한번에 넣어놓기보다는 필요할 때 추가하도록 하겠습니다!
this(null, firstName, lastName); | ||
} | ||
|
||
public Customer(Long id, String firstName, String lastName) { |
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.
strategy가 IDENTITY인데 id를 생성자로 받아야 할 필요가 없어 보입니다.
|
||
private String firstName; | ||
private String lastName; | ||
|
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.
이 둘, 연관성이 있어 보이지 않나요?
조금 더 관리하기 쉽게 만들 수 있을 것 같아요
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.
CustomerName
또는 Name
이라는 객체로 한꺼번에 관리할 수 있을 것 같습니다.
} | ||
|
||
@Transactional | ||
public CustomerResult create(CustomerCreateData customerCreateData) { |
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.
왜 create를 하고 result를 돌려주시려고 하신건지 생각이 궁금합니다.
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.
초기에는 전부 돌려주고 추후 필요한 정보만 돌려주도록 추가 작업을 하려고 했습니다.
create시에는 id
만 돌려주면 될 것 같고
추가 정보가 필요하다면 클라이언트가 /customer/{id}
를 통해 추가로 정보를 얻는 방식이 바람직해보입니다.
private CustomerService service; | ||
|
||
|
||
@BeforeEach |
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.
개행
|
||
@DataJpaTest | ||
class CustomerServiceTest { | ||
|
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.
Service 테스트인데, DataJpaTest 어노테이션을 사용하는건 아닌것 같습니다
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.
mock
을 이용하여 단위 테스트를 진행하도록 하겠습니다.
@Test | ||
void findById_존재하는아이디인경우_고객정보반환() { | ||
// Given | ||
CustomerCreateData creatingData = new CustomerCreateData("FirstName", "LastName"); | ||
CustomerResult createdResult = service.create(creatingData); | ||
|
||
Long existingId = createdResult.id(); | ||
|
||
// When | ||
CustomerResult foundResult = service.findById(existingId); | ||
|
||
// Then | ||
assertThat(foundResult.id()).isEqualTo(existingId); | ||
assertThat(foundResult) | ||
.usingRecursiveComparison() | ||
.ignoringFields("id") | ||
.isEqualTo(createdResult); | ||
} | ||
|
||
@Test | ||
void findById_존재하지않는아이디인경우_예외발생() { | ||
// Given | ||
Long nonExistingId = 0L; | ||
|
||
// When & Then | ||
assertThatThrownBy(() -> service.findById(nonExistingId)) | ||
.isInstanceOf(CustomerNotFoundException.class); | ||
} |
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.
좋네요. existingId, nonExistsingId
// Given | ||
CustomerCreateData creatingData = new CustomerCreateData("FirstName", "LastName"); | ||
CustomerResult createdResult = service.create(creatingData); | ||
|
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.
ting인지 ted인지 통일성을 맞춰주면 어떨까요? ing는 맞지 않는것같다고 생각하는데 어떻게 생각하세요?
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 savingItem = new Item("과자");
// 아이템 저장
Item savedItem = itemRepositroy.save(savingItem);
이런 식으로 작성하였는데, savingItem
변수명이 이상하다고 생각이 듭니다.
처음엔 itemToSave
를 사용하려고 하였는데, 변수명에 To
가 붙는 게 이상하다고 생각이 들어서요
변수명에 To
를 붙여도 괜찮을까요? 아니면 더 좋은 변수명이 있을까요?
|
||
@Test | ||
void findAll() { | ||
List<Order> orderAllList = orderRepository.findAll(); | ||
|
||
log.info("orderAllList = {}", orderAllList); | ||
} | ||
|
||
@Test | ||
void findOne() { | ||
Optional<Order> retrievedOrder = orderRepository.findByIdWithOrderLineItemsAndItems( | ||
savedOrder.getId()); | ||
log.info("{}", retrievedOrder.get()); | ||
} |
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.
라이브러리를 테스트하려면 다른 제공하는것들도 다 하셔야 한다고 생각합니다.
📌 과제 설명
과제를 페이프로그래밍으로 진행하였습니다.
👩💻 요구 사항과 구현 내용
✅ 피드백 반영사항
✅ PR 포인트 & 궁금한 점