Skip to content

[Feature] 상품-카테고리 매핑#199

Merged
Bal1oon merged 7 commits into
developfrom
feature/#191-mapping-product-category
Oct 25, 2025
Merged

[Feature] 상품-카테고리 매핑#199
Bal1oon merged 7 commits into
developfrom
feature/#191-mapping-product-category

Conversation

@Bal1oon

@Bal1oon Bal1oon commented Oct 25, 2025

Copy link
Copy Markdown
Contributor

🛠️ Issue Number

closes #191

📌 작업 내용 및 특이사항

Product ↔ Category 연관관계 추가

  • Product 엔티티에 @ManyToOne으로 Category 필드 추가
  • 상품은 반드시 최하위(Depth=3) 카테고리에만 속할 수 있도록 검증 추가 (변경 가능성 존재)
    • createProduct()updateCategory()에서 depth 검증 로직 수행
    • 잘못된 카테고리일 경우 CategoryErrorCode.INVALID_CATEGORY_DEPTH 발생

상품 생성/수정 시 카테고리 연동

PATCH /products/{productId}/categories
  • ProductCreateRequestcategoryId 필드 추가
  • ProductService.createProduct()에서 Category 조회 및 유효성 검증 수행
  • ProductService.updateProductCategory() 메서드 추가로 카테고리 변경 API 분리

카테고리별 상품 조회 구현

GET /products?categoryId={uuid}
  • /products API에서 categoryId@RequestParam으로 받도록 수정
  • 조회 조건 설정
    • categoryId만 있으면 해당 카테고리 및 하위 카테고리 전체 상품 조회
    • keyword만 있으면 전체 상품 중 검색어 일치 상품 조회
    • categoryId + keyword 함께 있으면 AND 조건으로 필터링
  • getProductList() 로직 개선
    • categoryId가 있을 경우 하위 카테고리까지 포함하여 조회
    • 예시) '생활용품' -> '헤어' -> '샴푸', '린스' 카테고리가 있을 때, '헤어'로 필터링을 걸면 '샴푸', '린스' 상품이 함께 조회됨

📚 참고사항

@Bal1oon Bal1oon added this to the Sprint 3 milestone Oct 25, 2025
@Bal1oon Bal1oon self-assigned this Oct 25, 2025
@Bal1oon Bal1oon added the ✨ feature 새 기능을 추가합니다. label Oct 25, 2025

@willjsw willjsw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

고생하셨습니다! 몇가지 궁금한 부분 질문 남겼는데, 시간 되실 때 고려해보시고 답변 남겨주시면 감사하겠습니다:)

Comment on lines +91 to +93
if (category.getDepth() != 3) {
throw new CommonException(CategoryErrorCode.INVALID_CATEGORY_DEPTH);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P4: 필터링 로직은 Service 단에서 CategoryId 존재 유무와 함께 검증해도 될 것 같은데, 고려해보셔도 좋을 듯 합니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

depth가 3이어야 한다는 검증은 도메인 규칙이라, Product 엔티티 내부에서 일관성을 보장하도록 검증을 내부 처리했습니다.
엔티티 내부에서 검증을 유지하면 다른 Service나 이벤트 리스너 등에서 Product를 변경할 때도 동일한 규칙이 유지될 수 있기 때문에 안전하다고 생각했습니다.

다른 얘기지만, 저희가 카테고리를 어떻게 구성할 지 모르겠지만 카테고리 계층이 항상 3단계를 이루지 않을 수 있어 해당 검증에 대해서는 변경이 이뤄질 수 있습니다 (쿠팡은 2계층까지만 이뤄지는 카테고리가 존재합니다)

Comment on lines 208 to +394
@@ -338,4 +378,18 @@ public void deleteProductOptionValue(UUID optionValueId) {
optionValueRepository.delete(optionValue);
log.info("상품 옵션 값 삭제 완료: valueId={}", optionValueId);
}

private List<UUID> getAllDescendantCategoryIds(UUID categoryId) {
List<UUID> ids = new ArrayList<>();
collectDescendants(categoryId, ids);
return ids;
}

private void collectDescendants(UUID categoryId, List<UUID> ids) {
ids.add(categoryId);
List<Category> children = categoryRepository.findChildrenByParentId(categoryId);
for (Category child : children) {
collectDescendants(child.getCategoryId(), ids);
}
}

@willjsw willjsw Oct 25, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P3: 제가 이해한게 맞다면 collectDescendants을 재귀호출하면서, 최초로 입력한 카테고리 아이디가 루트가 되어 모든 하위 노드들에 대한 상품을 리스트로 반환하는 로직인 것 같습니다. 그리고 ProductResponse DTO 의 필드에 현재 카테고리 아이디가 포함되어 있지 않은 것같습니다.
현재 저희가 UI 단까지 고려하고 있지는 않지만, 최하위 레벨이 아닌 카테고리 아이디를 넣으면 분류할 수 있는 기준 없이 하위 카테고리 상품이 조회되는 것이 아닌지, 이 경우 사용자 입장에서 조회에 문제는 없을 지 고려해볼만 한 것 같습니다.
DTO에 카테고리 아이디를 필드로 포함하고 FE 단에서 해당 필드를 기준으로 정렬해서 화면을 구성하는 것을 상정해보면 어떨까요? 검토해보시고 의견 주세요!
어려운 부분이었는데 고민을 많이 하신 것 같습니다!👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

조회 로직 쪽만 신경을 쓰고 Response DTO에 대해서는 고려하지 못했었네요.
좋은 의견 감사합니다! 반영해서 수정해보겠습니다 👍

@isak-kang

Copy link
Copy Markdown
Contributor

고생하셨습니다!

@Bal1oon
Bal1oon merged commit a972185 into develop Oct 25, 2025
1 check passed
growingpsy pushed a commit that referenced this pull request Oct 26, 2025
* feature #191: 상품 카테고리 생성 및 수정 구현

* feature #191: 카테고리 별 상품 목록 조회 구현

* refactor #191: Spotless 적용

* refactor #191: Spotless 적용

* feature #191: Response 카테고리 필드 추가

* feature #191: 상품 상세 조회 DTO 카테고리 필드 추가

* refactor #191: Spotless 적용
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ feature 새 기능을 추가합니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 카테고리 별 상품 목록 조회 구현

3 participants