-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: 사장님 상점 최초 등록 API #239
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
Conversation
1. Response를 ShopResponse에서 EmptyResponse로 변경하여 아무것도 반환하지 않도록 변경 2. CreateShop 요청에 대한 DTO to Domain 변환을 update 메서드를 추가하여 진행 3. ShopConverter 오타 수정 4. SQL문 수정 - 불필요한 insert value 제거 - selectkey를 통하여 insert 완료된 행의 id를 반환하도록 작성
1. 메서드명 변경 (다중정의 해제) 2. 파라미터 제거
…ature/create-owner-shop
…b/KOIN_API into feature/create-owner-shop
Invidam
left a comment
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.
코드 리뷰 남겼으니 확인부탁드려요~
자바 스터디 하며 배웠던 내용들을
실제 프로젝트에도 적용해보는 건 어렵지만
본인에게 큰 도움이 될테니 이런 기회에 시도해보면 좋을 것 같아요!
src/main/java/koreatech/in/dto/normal/shop/request/CreateShopRequest.java
Show resolved
Hide resolved
| @NotEmpty(message = "소속시킬 상점 카테고리는 최소 1개 선택하여야합니다.") | ||
| @ApiModelProperty(notes = "상점 카테고리 고유 id 리스트 \n" + | ||
| "- not null \n" + | ||
| "- 최소 1개", example = "[1, 4]", required = true) |
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.
스웨거에서 리스트를 Example Value에 작성하는 방법을 찾을 수 없었습니다..
따라서 기존 AllShopsResponse와 같이 example을 제거하는 방향으로 진행하였습니다.
src/main/java/koreatech/in/dto/normal/shop/request/CreateShopRequest.java
Outdated
Show resolved
Hide resolved
| }) | ||
| @ParamValid | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| @RequestMapping(value = "", method = RequestMethod.POST) |
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.
PUT /admin/shops 에서 s가 꼭 붙어야 할까요?
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.
메서드 단의 RequestMapping에서 클래스 단의 매핑값을 지우는 방법은 찾지 못해서 이렇게 작성했습니다..
src/main/java/koreatech/in/dto/normal/shop/request/CreateShopRequest.java
Show resolved
Hide resolved
| // ======= shop_opens 테이블 ======= | ||
| List<ShopOpen> shopOpens = generateShopOpensAndGetForCreate(request.getOpen(), shop.getId()); | ||
| shopMapper.createShopOpens(shopOpens); | ||
|
|
||
| // ======= shop_category_map 테이블 ======= | ||
| checkShopCategoriesExistInDatabase(request.getCategory_ids()); | ||
|
|
||
| List<ShopCategoryMap> shopCategoryMaps = generateShopCategoryMapsAndGet(shop.getId(), request.getCategory_ids()); | ||
| shopMapper.createShopCategoryMaps(shopCategoryMaps); | ||
|
|
||
| // ======= shop_images 테이블 ======= | ||
| List<ShopImage> shopImages = generateShopImagesAndGet(shop.getId(), request.getImage_urls()); | ||
| shopMapper.createShopImages(shopImages); | ||
| } |
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 계층에서 Presentation 계층인 테이블 정보가 주석에 나와있습니다. Nosql로 DB를 변경하게 된다면 Service 계층의 코드들까지 변경이 일어날 것 같아요.
- 메서드 명이 전반적으로 너무 길어 이해하기가 어렵네요 ㅠ
아래와 같은 규칙들을 적용해볼 수 있을 것 같아요
추천 규칙
- (외부에서 바라보는) 한 가지 역할만을 명시한다:
generateShopImagesAndGet()->generateShopImages()
- 반환 타입, 인자를 이용하여 표현한다.
List<ShopImage> generateFor(Integer shopId, List<String> imageUrls)
(극단적으로 줄인 경우)
위 메서드 명만 있어도
shopId, imageUrls을 통해 List<ShopImage>를 generate 한다는 걸 알 수 있을 것 같아요
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.
수정하겠습니다!
Swagger example value에 리스트가 문자열로 표기되는 현상 수정
|
추가적으로 진행한 테스트
|
| boolean hasEmptyTimeInformation = this.open.stream() | ||
| .filter(open -> !open.getClosed()) | ||
| .anyMatch(open -> open.getOpen_time() == null || open.getClose_time() == null); | ||
|
|
||
| for (Open open : this.open) { | ||
| DayOfWeek dayOfWeek = open.getDay_of_week(); | ||
| Boolean closed = open.getClosed(); | ||
| String openTime = open.getOpen_time(); | ||
| String closeTime = open.getClose_time(); | ||
|
|
||
| if (!closed) { | ||
| if (openTime == null || closeTime == null) { | ||
| throw new BaseException(TIME_INFORMATION_IS_REQUIRED_UNLESS_CLOSED); | ||
| } | ||
| } | ||
|
|
||
| dayOfWeeksWithoutDuplication.add(dayOfWeek); | ||
| if (hasEmptyTimeInformation) { | ||
| throw new BaseException(TIME_INFORMATION_IS_REQUIRED_UNLESS_CLOSED); | ||
| } | ||
|
|
||
| if (dayOfWeeksWithoutDuplication.size() != 7) { | ||
| boolean hasDuplicateDayOfWeek = this.open.stream() | ||
| .map(Open::getDay_of_week) | ||
| .distinct() | ||
| .count() != 7; | ||
|
|
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.
👍
리팩터링 이후 테스트도 다시 된거죠??
| @ApiModelProperty(notes = "상점 카테고리 고유 id 리스트 \n" + | ||
| "- not null \n" + | ||
| "- 최소 1개", example = "[1, 4]", required = true) | ||
| "- 최소 1개", required = true) |
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.
|
|
||
| List<ShopCategoryMap> existingShopCategoryMaps = shopMapper.getShopCategoryMapsByShopId(existingShop.getId()); | ||
|
|
||
| // IGNORE에 의하여 (shop_id, shop_category_id)가 중복일 경우는 insert가 무시된다. |
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.
createShopCategoryMaps와 createShopImages에 사용된 이유
기존에 IGNORE이 사용된 이유에 대해 찾아봤는데,
카테고리 입력을 예로 들자면
집합의 업데이트에서 기존 카테고리들와 입력한 카테고리들의 교집합을 걸러내기 위해 IGNORE이 필요하네요
예시
기존 카테고리들: {1,2,3,4,5}
입력 카테고리들: {1,2,7,8,9}
교집합: {1,2}
- 입력 카테고리들: {1,2,7,8,9} -> createShopCategoryMaps 에 들어옴
- {7,8,9} 는 INSERT 처리
- {1,2} 는 INSERT 되나 duplicate되어 IGNOORE 처리
- 삭제할 카테고리들 : {3,4,5} -> deleteShopImages 로 제거

결과
입력 이전 저장된 카테고리들: {1,2,3,4,5}
입력 이후 저장된 카테고리들: {1,2,7,8,9}
결론
-> IGNORE이 없다면? (3)에서 500에러가 터졌을 것
=> 리스트(집합)의 업데이트시 사용
|
변경 사항category_ids 관련 Swagger 문서 설명 추가 다시 진행된 테스트
|




▶ Request
Content
#227
as-is
사장님이 상점을 직접 등록하는 API가 존재하지 않아 수동으로 상점을 추가해주어야 했음.
to-be
사장님이 자신이 소유한 상점 정보를 직접 등록할 수 있도록 하는 API를 작성함.
참고사항
요청을 보낼 때 상점 정보 json에 들어있는 open 리스트 (상점 운영시간) 의 길이는 반드시 7이어야 함.
(일주일 요일 수)
INSERT 대상 테이블
✅ Check List
pom.xml) 변경이 일어나지 않았는지📸 API Document ScreenShot
🧪 Test