[5기 - 정의진] SpringBoot Part3 Weekly Mission 제출합니다.#969
[5기 - 정의진] SpringBoot Part3 Weekly Mission 제출합니다.#969uijin-j wants to merge 134 commits intoprgrms-be-devcourse:mainfrom
Conversation
################ # <타입> : <제목> 의 형식으로 제목을 아래 공백줄에 작성 # 제목은 50자 이내 / 변경사항이 "무엇"인지 명확히 작성 / 끝에 마침표 금지 # 예) feat : 로그인 기능 추가 # 바로 아래 공백은 지우지 마세요 (제목과 본문의 분리를 위함) ################ # 본문(구체적인 내용)을 아랫줄에 작성 # 여러 줄의 메시지를 작성할 땐 "-"로 구분 (한 줄은 72자 이내) ################ # 꼬릿말(footer)을 아랫줄에 작성 (현재 커밋과 관련된 이슈 번호 추가 등) # 예) Close prgrms-be-devcourse#7 ################ # feat : 새로운 기능 추가 # fix : 버그 수정 # docs : 문서 수정 # test : 테스트 코드 추가 # refact : 코드 리팩토링 # style : 코드 의미에 영향을 주지 않는 변경사항 # chore : 빌드 부분 혹은 패키지 매니저 수정사항 ################
################ # <타입> : <제목> 의 형식으로 제목을 아래 공백줄에 작성 # 제목은 50자 이내 / 변경사항이 "무엇"인지 명확히 작성 / 끝에 마침표 금지 # 예) feat : 로그인 기능 추가 # 바로 아래 공백은 지우지 마세요 (제목과 본문의 분리를 위함) ################ # 본문(구체적인 내용)을 아랫줄에 작성 # 여러 줄의 메시지를 작성할 땐 "-"로 구분 (한 줄은 72자 이내) ################ # 꼬릿말(footer)을 아랫줄에 작성 (현재 커밋과 관련된 이슈 번호 추가 등) # 예) Close prgrms-be-devcourse#7 ################ # feat : 새로운 기능 추가 # fix : 버그 수정 # docs : 문서 수정 # test : 테스트 코드 추가 # refact : 코드 리팩토링 # style : 코드 의미에 영향을 주지 않는 변경사항 # chore : 빌드 부분 혹은 패키지 매니저 수정사항 ################
Voucher 필드 게터 추가
조회, 생성, 삭제
메서드 분리, 상수 분리
메서드명 리네임, 메서드 분리
기능 구현이 완료되면, 다시 서비스
| public JdbcTemplateConfig(@Value("${spring.datasource.username}") String username, | ||
| @Value("${spring.datasource.password}") String password, | ||
| @Value("${spring.datasource.driver-class-name}") String driverClassName, | ||
| @Value("${spring.datasource.url}") String url) { |
There was a problem hiding this comment.
https://rutgo-letsgo.tistory.com/93
@ConfigurationProperties를 한번 알아보면 어떨까요?
| if(voucherType != null) { | ||
| List<VoucherResponse> vouchers = voucherService.getVouchersByVoucherType(voucherType).stream() | ||
| .map(VoucherResponse::of) | ||
| .toList(); | ||
|
|
||
| return ApiResponse.ok(vouchers); | ||
| } | ||
|
|
||
| List<VoucherResponse> vouchers = voucherService.getVouchers().stream() | ||
| .map(VoucherResponse::of) | ||
| .toList(); | ||
|
|
||
| return ApiResponse.ok(vouchers); |
There was a problem hiding this comment.
이글을 참고해서 한번 fitlering builder패턴? 느낌을 한번 알아보면 어떨까요?
| public ApiResponse deleteVoucher(@PathVariable Long voucherId) { | ||
| voucherService.deleteVoucher(voucherId); | ||
|
|
||
| return ApiResponse.ok(); |
| } | ||
|
|
||
| @PostMapping | ||
| public String createVoucher(@RequestParam("voucherType") String voucherType, |
There was a problem hiding this comment.
| public String createVoucher(@RequestParam("voucherType") String voucherType, | |
| public String createVoucher(@RequestParam String voucherType, |
이거 생략해도 무관해요~
| private static boolean isNotPositive(int discountValue) { | ||
| return discountValue <= 0; | ||
| } | ||
|
|
||
| private static void validateDiscountValue(int discountValue) { | ||
| if (isNotPositive(discountValue)) throw new IllegalArgumentException("할인 금액 또는 할인율은 양수입니다."); | ||
| } |
| private void getMyVouchers(UUID customerId) { | ||
| // TODO | ||
| } | ||
|
|
||
| private void registerVoucher(UUID customerId) { | ||
| // TODO | ||
| } |
| import java.util.NoSuchElementException; | ||
| import java.util.UUID; | ||
|
|
||
| @Controller |
| <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto'> | ||
| <script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script> | ||
| <style> | ||
| body { |
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| @SpringBootTest |
| voucherRepository.save(voucher3); | ||
|
|
||
| // when | ||
| Optional<Long> latestId = voucherRepository.findLatestVoucherId(); |
| if (isNotPositive(discountValue)) throw new IllegalArgumentException("할인 금액 또는 할인율은 양수입니다."); | ||
| } | ||
|
|
||
| private static boolean isNotPositive(int discountValue) { |
There was a problem hiding this comment.
과도한 분리 같습니다. 그리고 0같은 magic number를 상수로 표현하면 더 좋을 것 같습니다.
|
|
||
| import java.util.UUID; | ||
|
|
||
| public class CustomerIdAndName { |
There was a problem hiding this comment.
dto에서 반복되는 보일러 플레이트 코드들을 record를 이용하면 줄일 수 있을 것 같습니다.
| Voucher voucher = voucherService.createVoucher(request.toServiceRequest()); | ||
| VoucherResponse response = VoucherResponse.of(voucher); | ||
|
|
||
| return ApiResponse.ok(response); |
| customer.getEmail(), | ||
| Timestamp.valueOf(customer.getCreatedAt())); | ||
|
|
||
| if(update != 1) { |
There was a problem hiding this comment.
1의 의미를 잘 표현할 수 있는 상수를 만들면 좋을 것 같습니다.
| public Optional<Voucher> findById(Long voucherId) { | ||
| if(voucherMap.containsKey(voucherId)) { | ||
| return Optional.of(voucherMap.get(voucherId)); | ||
| } else return Optional.empty(); |
There was a problem hiding this comment.
else 없이 아래에서 return 하는게 더 이해하기 좋을 것 같습니다.
|
|
||
| Customer customer = customerController.findCustomerByEmail(customerEmail); | ||
|
|
||
| if(customer == null) { |
There was a problem hiding this comment.
null인 경우가 있다면 Optional로 인지할 수 있게 구성하면 좋을 것 같습니다.
| } | ||
|
|
||
| private void getMyVouchers(UUID customerId) { | ||
| // TODO |
There was a problem hiding this comment.
아직 구현되지 않았다면 exception으로 표현해두는 것도 좋을 것 같습니다.
📌 과제 설명
바우처 관리 어플리케이션
👩💻 요구 사항과 구현 내용
(기본) 바우처 서비스 관리페이지 개발하기
(기본) 바우처 서비스의 API 개발하기
Spring MVC를 적용해서 JSON과 XML을 지원하는 REST API를 개발해보세요
(보너스) 바우처 지갑용 관리페이지를 만들어보세요.
✅ 피드백 반영사항
(참고) 지갑 서비스(console app, web)는 개발 도중 일정이 촉박해서 아직 미완성 단계입니다! 그래서 console app 런처에 지갑 서비스가 표시되지만 선택하면 '지갑 서비스는 준비 중입니다.'라는 문구가 나오도록 해놨습니다.
✅ 실행 방법
Docker MySQL DB 연결 방법
❗3305번 포트를 혹시 사용 중이시라면, 사용 가능한 포트 번호로 변경해주세요!
src/main/resources/schema.sql스트립트를 실행해서 테이블을 생성할 수 있습니다:)src/main/resources/data.sql스트립트를 실행해서 customers 테이블에 테스트 데이터를 삽입할 수 있습니다:)✅ PR 포인트 & 궁금한 점