-
Notifications
You must be signed in to change notification settings - Fork 171
[5기 - 조인수] SpringBoot Part 3 Weekly Mission 제출합니다. #974
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: zzambas
Are you sure you want to change the base?
Conversation
src/main/java/org/prgms/springbootbasic/controller/voucher/VoucherApiController.java
Outdated
Show resolved
Hide resolved
public VoucherResponseDto update(VoucherUpdateDto voucherUpdateDto) { | ||
UUID voucherId = voucherUpdateDto.voucherId(); | ||
|
||
findById(voucherId).orElseThrow(EntityNotFoundException::new); |
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.
- 이 부분에서 update를 위해 실제 DB에 해당하는 Voucher가 존재하는지 확인합니다.
|
||
@Override | ||
public Voucher upsert(Voucher voucher) { | ||
Optional<Voucher> foundVoucher = findById(voucher.getVoucherId()); // 재사용 지양 |
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.
- 그런데 여기서 또 다시 확인합니다.
VoucherRepository
내upsert()
메서드를insert()
,update()
로 나누는 것이 좋을까요?
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.
upsert가 필요하다면 굳이 나눌 필요 없이 이를 활용해도 좋을 것 같아요 👍
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.
3주차 과제까지 반영해주시느라 고생많으셨어요!
JPA때 더 열심히 달려봐요 😄
📌 과제 설명
(기본) 바우처 서비스 관리페이지 개발하기
(기본) 바우처 서비스의 API 개발하기
Spring MVC를 적용해서 JSON과 XML을 지원하는 REST API를 개발해보세요
(보너스) 바우처 지갑용 관리페이지를 만들어보세요.
👩💻 요구 사항과 구현 내용
Controller를 추가하여 thymeleaf에서 뷰를 보여주거나 rest api 통신이 가능하도록 하였습니다.
✅ 피드백 반영사항
part2까지 반영사항
@DisplayName()
을 붙여 어떤 테스트인지 알기 쉽도록 한 곳도 있습니다.part3 반영 사항 (2023-11-18)
VoucherResponseDto
내부convertVoucherToVoucherResponseDto()
메서드)VoucherFilterDto
로 변환한 뒤, 서비스에 전달합니다. 즉, 컨트롤러와 서비스 사이에서도 Dto를 적용합니다. 역시나Voucher
라는 도메인 자체를 컨트롤러에 숨기기 위함이며, 서비스에서도 필요한 정보만 파라미터로 받을 수 있게 되었습니다.(2023-11-19)
DTO의 영역을 Model 영역으로 생각하여 Controller 패키지에 존재했던 DTO들을 Service 패키지로 전부 이동시켰습니다. 이제 VoucherService에서 Controller 부분과 의존하는 부분은 존재하지 않게 됩니다. 이에 따라 컨트롤러에서의 수정이 모델에 아무 영향을 끼치지 않을 것을 기대할 수 있습니다.
✅ PR 포인트 & 궁금한 점
insert(Dto dto)
와insert(VoucherType voucherType, long discountDegree)
이런 식입니다!(2023-11-19)
VoucherRepository
에upsert
메서드가 구현되어 있고 그 메서드에서는VoucherRepository
의findById()
를 호출하여 select 문으로 검색하여 있으면 UPDATE, 없으면 INSERT를 합니다. 그런데VoucherService
의 메서드는insert()
와update()
로 나누어서 생성하였고, insert는 문제가 없는데 update는 일단 서비스 로직 내에서findById()
를 실행하고 해당하는 Voucher가 존재하면, 다시VoucherRepository
의upsert()
메서드를 실행하는데 역시나 여기서 또 select 문을 실행합니다.찾는 쿼리가 2번이나 나가는데, 설계부터 문제가 있는건지 아니면 다른 해결법이 있는지 궁금합니다. 그냥
VoucherRepository
내 메서드를upsert()
에서insert()
,update()
로 나누어야 할까요?아래 코드에 관련 코멘트를 남겼습니다!