Skip to content

refactor: 추천 상품 로직을 인기 상품 기반으로 단순화#164

Merged
neibler merged 2 commits intodevelopfrom
feature/161
Feb 19, 2026
Merged

refactor: 추천 상품 로직을 인기 상품 기반으로 단순화#164
neibler merged 2 commits intodevelopfrom
feature/161

Conversation

@neibler
Copy link
Copy Markdown
Contributor

@neibler neibler commented Feb 19, 2026

🔍️ 작업 내용

  • Closes #

✨ 상세 설명

🛠️ 추후 리팩토링 및 고도화 계획

📸 스크린샷 (선택)

💬 리뷰 요구사항

Summary by CodeRabbit

  • 개선 사항
    • 홈 화면 추천이 맞춤형에서 인기 상품 기반으로 단순화되었습니다.
    • 추천 요청이 더 이상 인증 정보에 의존하지 않으므로 로그인 없이도 동일한 크기(size) 파라미터로 인기 추천을 받을 수 있습니다.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 19, 2026

Walkthrough

상품 추천의 개인화 로직을 제거하고 추천 엔드포인트를 인기상품 기반으로 단순화했습니다. ProductRepository에서 개인화 관련 쿼리 메서드 2개를 삭제했고, ProductService와 ProductController에서 사용자 기반 분기·의존성·헬퍼 메서드를 제거하여 getRecommendedProducts(size)로 변경했습니다.

Changes

Cohort / File(s) Summary
Repository 쿼리 메서드 제거
src/main/java/com/ongil/backend/domain/product/repository/ProductRepository.java
개인화 추천(findRecommendedProducts)과 판매 상품 배치 조회(findByIdInAndOnSaleTrue) 쿼리 메서드 2개 삭제(관련 EntityGraph 및 JPQL 제거).
Service 개인화 로직 제거
src/main/java/com/ongil/backend/domain/product/service/ProductService.java
CartRepository, OrderItemRepository 의존성 및 PRICE_RANGE, DAYS_TO_LOOK_BACK 상수 제거; 로그인 기반 분기와 개인화 헬퍼(getPopularProducts(), getPersonalizedRecommendations()) 삭제; getRecommendedProducts 시그니처를 (int size)로 변경하고 인기상품 조회로 단순화.
Controller 시그니처/호출 변경
src/main/java/com/ongil/backend/domain/product/controller/ProductController.java
인증된 사용자 파라미터 제거 및 서비스 호출을 productService.getRecommendedProducts(size)로 변경하여 사용자 개인화 제거.

Sequence Diagram(s)

mermaid
sequenceDiagram
rect rgba(200,200,255,0.5)
participant Client
end
rect rgba(200,255,200,0.5)
participant Controller
end
rect rgba(255,200,200,0.5)
participant Service
end
rect rgba(255,240,200,0.5)
participant ProductRepository
end
rect rgba(240,200,255,0.5)
participant CartRepository
end
rect rgba(200,255,255,0.5)
participant OrderItemRepository
end

Note right of Controller: 이전 흐름 (개인화)
Client->>Controller: GET /recommended (with userId)
Controller->>Service: getRecommendedProducts(userId, size)
Service->>CartRepository: fetch user cart
Service->>OrderItemRepository: fetch user order items
Service->>ProductRepository: findRecommendedProducts(...) / findByIdInAndOnSaleTrue(...)
ProductRepository-->>Service: personalized product list
Service-->>Controller: personalized response
Controller-->>Client: 200 OK (personalized)

Note right of Controller: 변경된 흐름 (단순 인기상품)
Client->>Controller: GET /recommended (no user)
Controller->>Service: getRecommendedProducts(size)
Service->>ProductRepository: findPopularProducts(pageable)
ProductRepository-->>Service: popular product list
Service-->>Controller: popular response
Controller-->>Client: 200 OK (popular)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

♻️ Refactor

Suggested reviewers

  • kangcheolung
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경 내용의 핵심을 명확하게 요약합니다. 추천 상품 로직을 인기 상품 기반으로 단순화했다는 주요 변경 사항을 직접 반영하고 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/161

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/com/ongil/backend/domain/product/service/ProductService.java`:
- Around line 382-383: Update the Javadoc in ProductService that currently reads
"인기 상품 순(viewCount + cartCount) 반환 - 특가 상품(SPECIAL_SALE) 제외" to remove any
reference to cartCount (since the DTO/response no longer includes it); change
the description to indicate popularity is determined by viewCount only and keep
the note about excluding SPECIAL_SALE, and ensure the updated comment sits above
the corresponding method in ProductService that returns popular products.
- Around line 385-389: Remove the unused userId parameter from the service API
and its callers: change the method signature of
ProductService.getRecommendedProducts(Long userId, int size) to
getRecommendedProducts(int size) and update its internal use (PageRequest.of(0,
size) remains unchanged) and references in ProductController (and any other
callers/tests) to call productService.getRecommendedProducts(size) instead of
passing a userId; also remove any now-unused imports or parameter-related code
and run tests to ensure no remaining references to the old signature.

Comment on lines +382 to +383
* - 인기 상품 순(viewCount + cartCount) 반환
* - 특가 상품(SPECIAL_SALE) 제외
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Javadoc 주석에서 cartCount 참조 제거 필요

cartCount는 이미 DTO/응답에서 제거된 필드인데 주석에 "viewCount + cartCount"가 여전히 명시되어 있어 혼란을 줄 수 있습니다.

📝 주석 수정 제안
-	 * - 인기 상품 순(viewCount + cartCount) 반환
+	 * - 인기 상품 순(viewCount 기반) 반환

Based on learnings: cartCount 필드는 프론트엔드에서 사용하지 않아 이미 제거된 상태입니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* - 인기 상품 (viewCount + cartCount) 반환
* - 특가 상품(SPECIAL_SALE) 제외
* - 인기 상품 (viewCount 기반) 반환
* - 특가 상품(SPECIAL_SALE) 제외
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/ongil/backend/domain/product/service/ProductService.java`
around lines 382 - 383, Update the Javadoc in ProductService that currently
reads "인기 상품 순(viewCount + cartCount) 반환 - 특가 상품(SPECIAL_SALE) 제외" to remove any
reference to cartCount (since the DTO/response no longer includes it); change
the description to indicate popularity is determined by viewCount only and keep
the note about excluding SPECIAL_SALE, and ensure the updated comment sits above
the corresponding method in ProductService that returns popular products.

Comment on lines 385 to 389
public List<ProductSimpleResponse> getRecommendedProducts(Long userId, int size) {
if (userId == null) {
return getPopularProducts(size);
}
return getPersonalizedRecommendations(userId, size);
}

/**
* 인기 상품 조회
*/
private List<ProductSimpleResponse> getPopularProducts(int size) {
Pageable pageable = PageRequest.of(0, size);
List<Product> products = productRepository.findPopularProducts(pageable);
return productConverter.toSimpleResponseList(products);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find the ProductService file and check the getRecommendedProducts method
fd ProductService.java --type f

Repository: IT-Cotato/12th-OnGil-BE

Length of output: 141


🏁 Script executed:

# Search for getRecommendedProducts calls in the codebase
rg -n "getRecommendedProducts" --type java -A 3 -B 3

Repository: IT-Cotato/12th-OnGil-BE

Length of output: 2253


🏁 Script executed:

# Check the ProductController to see how it calls this method
fd ProductController.java --type f

Repository: IT-Cotato/12th-OnGil-BE

Length of output: 147


서비스 메서드에서 사용되지 않는 userId 파라미터 제거

getRecommendedProducts(Long userId, int size) 메서드에서 userId는 메서드 본문 어디에서도 참조되지 않습니다. 컨트롤러에서 불필요하게 이 파라미터를 전달하고 있으므로, 양쪽 모두에서 제거하는 것이 코드의 명확성을 높입니다.

♻️ 리팩토링 제안

서비스:

-	public List<ProductSimpleResponse> getRecommendedProducts(Long userId, int size) {
+	public List<ProductSimpleResponse> getRecommendedProducts(int size) {
 		Pageable pageable = PageRequest.of(0, size);
 		List<Product> products = productRepository.findPopularProducts(pageable);
 		return productConverter.toSimpleResponseList(products);
 	}

컨트롤러:

-	public DataResponse<List<ProductSimpleResponse>> getRecommendedProducts(
-		`@AuthenticationPrincipal` Long userId,
-		`@RequestParam`(defaultValue = "10") `@Min`(1) `@Max`(100) int size
-	) {
-		List<ProductSimpleResponse> products = productService.getRecommendedProducts(userId, size);
+	public DataResponse<List<ProductSimpleResponse>> getRecommendedProducts(
+		`@RequestParam`(defaultValue = "10") `@Min`(1) `@Max`(100) int size
+	) {
+		List<ProductSimpleResponse> products = productService.getRecommendedProducts(size);
 		return DataResponse.from(products);
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/ongil/backend/domain/product/service/ProductService.java`
around lines 385 - 389, Remove the unused userId parameter from the service API
and its callers: change the method signature of
ProductService.getRecommendedProducts(Long userId, int size) to
getRecommendedProducts(int size) and update its internal use (PageRequest.of(0,
size) remains unchanged) and references in ProductController (and any other
callers/tests) to call productService.getRecommendedProducts(size) instead of
passing a userId; also remove any now-unused imports or parameter-related code
and run tests to ensure no remaining references to the old signature.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/ongil/backend/domain/product/controller/ProductController.java (1)

142-149: ⚠️ Potential issue | 🟡 Minor

@Operation 설명이 리팩토링 내용을 반영하지 않아 Swagger 문서가 부정확합니다

개인화 로직 제거 후에도 @Operation description이 구버전 동작을 그대로 기술하고 있습니다:

  • "로그인 사용자: 최근 30일간 조회/장바구니 상품 기준 …" → 해당 로직 삭제됨
  • "비로그인 사용자: 전체 인기 상품 추천" → 이제 로그인 여부 구분 없음
  • "정렬 기준: 전체 고객의 조회수 + 장바구니 담긴 횟수 순" → cartCount 기준 제거됨

API를 소비하는 프론트엔드나 Swagger 사용자가 잘못된 동작을 기대할 수 있습니다.

📝 설명 수정 제안
 `@Operation`(
     summary = "홈화면 추천 상품 조회",
     description = """
-        로그인 사용자: 최근 30일간 조회/장바구니 상품 기준 같은 카테고리 + 비슷한 가격대(±10,000원) 상품 추천
-        비로그인 사용자: 전체 인기 상품 추천
-
-        정렬 기준: 전체 고객의 조회수 + 장바구니 담긴 횟수 순
+        전체 인기 상품을 조회합니다.
+
+        정렬 기준: 전체 고객의 조회수(viewCount) 순
         """
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/com/ongil/backend/domain/product/controller/ProductController.java`
around lines 142 - 149, Update the `@Operation` description on ProductController
to reflect the refactor: remove any mention of per-user personalization ("로그인
사용자..." / "비로그인 사용자...") and remove reference to cartCount; state that the
endpoint returns general recommended products (same for all users) and that
sorting is based on overall view count only (or list the current actual sorting
metric used by the implementation). Edit the description string in the
`@Operation` annotation for the method in ProductController to match the current
behavior and wording used by the implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@src/main/java/com/ongil/backend/domain/product/controller/ProductController.java`:
- Around line 142-149: Update the `@Operation` description on ProductController to
reflect the refactor: remove any mention of per-user personalization ("로그인
사용자..." / "비로그인 사용자...") and remove reference to cartCount; state that the
endpoint returns general recommended products (same for all users) and that
sorting is based on overall view count only (or list the current actual sorting
metric used by the implementation). Edit the description string in the
`@Operation` annotation for the method in ProductController to match the current
behavior and wording used by the implementation.

---

Duplicate comments:
In `@src/main/java/com/ongil/backend/domain/product/service/ProductService.java`:
- Around line 382-383: Javadoc in ProductService still mentions "인기 상품
순(viewCount + cartCount) 반환" even though cartCount is not used; update the
comment in the ProductService class (the Javadoc block containing that line) to
remove the cartCount reference and accurately state the sorting criterion (e.g.,
"인기 상품 순(viewCount 기준) 반환" or similar) and keep the note about excluding
SPECIAL_SALE; ensure the modified text reflects the actual behavior implemented
by the related method(s) in ProductService.

@neibler neibler merged commit 5942472 into develop Feb 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant