Skip to content
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

feat(KL-94): sort products #48

Conversation

ohhamma
Copy link
Contributor

@ohhamma ohhamma commented Aug 15, 2024

πŸ“Œ μ—°κ΄€λœ 이슈

πŸ“ μž‘μ—… λ‚΄μš©

  • μƒν’ˆ μ •λ ¬ κΈ°λŠ₯ μΆ”κ°€
    • κΈ°μ€€ : μ’‹μ•„μš”μˆ˜, 평점, μƒμ„±μΌμž
    • λ°©ν–₯ : μ˜€λ¦„μ°¨μˆœ, λ‚΄λ¦Όμ°¨μˆœ
  • κ΄€λ ¨ ν…ŒμŠ€νŠΈμ½”λ“œ μˆ˜μ • 및 μΆ”κ°€

🌳 μž‘μ—… 브랜치λͺ…

  • KL-94/μƒν’ˆ-μ •λ ¬-κΈ°λŠ₯

πŸ“Έ μŠ€ν¬λ¦°μƒ· (선택)

πŸ’¬ 리뷰 μš”κ΅¬μ‚¬ν•­ (선택)

Summary by CodeRabbit

  • New Features

    • Introduced sorting functionality for product retrieval, allowing users to sort by attributes such as creation date and rating.
    • Added new fields for sorting options in product queries, enhancing user control over displayed results.
    • Included a new metric, like_count, for products, providing additional insight into user engagement.
  • Bug Fixes

    • Implemented error handling for invalid sorting options, ensuring users receive appropriate feedback for incorrect queries.
  • Tests

    • Expanded test coverage to include various sorting scenarios, validating the integrity of the product retrieval process with new sorting capabilities.

- μœ νš¨ν•˜μ§€ μ•Šμ€ μ •λ ¬ ν•„λ“œμ— λŒ€ν•œ μ˜ˆμ™Έ μΆ”κ°€
- μœ νš¨ν•œ μ •λ ¬ μ˜΅μ…˜μ— λŒ€ν•œ μƒμˆ˜ μΆ”κ°€
- μ •λ ¬ μ˜΅μ…˜μ„ 쿼리 λ§€κ°œλ³€μˆ˜λ‘œ λ°›μ•„ μ •λ ¬ν•˜λŠ” 둜직 μΆ”κ°€
- μž‘μ—…λ³„λ‘œ μ„œλΉ„μŠ€ λ©”μ†Œλ“œ 뢄리
  - ν•„ν„°λ§λœ base query 생성
    - total κ°’ λ°˜ν™˜
    - μƒν’ˆ λͺ©λ‘ λ°˜ν™˜
      - μ •λ ¬ 둜직 적용
  - νŽ˜μ΄μ§€λ„€μ΄μ…˜ 적용
@ohhamma ohhamma added the ✨ Feature μƒˆλ‘œμš΄ κΈ°λŠ₯ 개발 및 μš”μ²­ label Aug 15, 2024
@ohhamma ohhamma requested review from idealflower-k and min3m August 15, 2024 14:39
@ohhamma ohhamma self-assigned this Aug 15, 2024
Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent updates enhance the product retrieval system by introducing sorting capabilities, allowing users to specify sorting criteria for product listings. Key changes include new parameters in service and controller methods, the introduction of a ProductSortOptionsDto for encapsulating sorting options, and enhanced error handling for invalid sorting requests. These modifications promote a more flexible and user-friendly experience when fetching products.

Changes

Files Change Summary
src/main/java/taco/klkl/domain/product/controller/ProductController.java, .../service/ProductService.java Enhanced getProducts and getProductsByFilterOptions methods to support sorting with new parameters and DTOs, improving product retrieval flexibility.
src/main/java/taco/klkl/domain/product/dto/request/ProductSortOptionsDto.java Introduced ProductSortOptionsDto as a record to encapsulate sorting options for product queries.
src/main/java/taco/klkl/domain/product/exception/InvalidSortOptionException.java Added a custom exception for handling invalid sort options, extending CustomException to improve error handling.
src/main/java/taco/klkl/global/common/constants/ProductConstants.java Added constants for allowed sorting criteria and directions to enhance configurability.
src/main/java/taco/klkl/global/error/exception/ErrorCode.java Introduced INVALID_SORT_OPTION to the error codes, improving error handling for sorting functionality.
src/main/resources/database/data.sql Modified SQL insert statements for the Product table to include a new like_count column, enhancing the data schema for additional metrics.
src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java Updated tests to reflect the new sorting capabilities in the getProducts method, ensuring correct handling of sorting parameters.
src/test/java/taco/klkl/domain/product/integration/ProductIntegrationTest.java Enhanced integration tests with additional cases for sorting, verifying correct product ordering based on new sorting options.
src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java Updated service tests to include sorting in the getProductsByFilterOptions method, validating that sorting behavior is handled correctly in queries.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProductController
    participant ProductService
    participant ProductRepository
    
    Client->>ProductController: Request products (sort_by, sort_direction)
    ProductController->>ProductService: getProductsByFilterOptions(pageable, filterOptions, sortOptions)
    ProductService->>ProductRepository: fetchProducts(baseQuery, pageable, sortOptions)
    ProductRepository-->>ProductService: Return sorted products
    ProductService-->>ProductController: Return paged response
    ProductController-->>Client: Return product list
Loading

πŸ‡πŸŒΈ In a world where products abound,
Sorting options now are found!
With like counts tallied high,
Fetching goods is now a pie!
So hop along, dear friends, rejoice,
For choice and order now are voice! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ohhamma
Copy link
Contributor Author

ohhamma commented Aug 15, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Aug 15, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aca6e93 and c7e1140.

Files selected for processing (10)
  • src/main/java/taco/klkl/domain/product/controller/ProductController.java (2 hunks)
  • src/main/java/taco/klkl/domain/product/dto/request/ProductSortOptionsDto.java (1 hunks)
  • src/main/java/taco/klkl/domain/product/exception/InvalidSortOptionException.java (1 hunks)
  • src/main/java/taco/klkl/domain/product/service/ProductService.java (6 hunks)
  • src/main/java/taco/klkl/global/common/constants/ProductConstants.java (2 hunks)
  • src/main/java/taco/klkl/global/error/exception/ErrorCode.java (1 hunks)
  • src/main/resources/database/data.sql (1 hunks)
  • src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java (5 hunks)
  • src/test/java/taco/klkl/domain/product/integration/ProductIntegrationTest.java (8 hunks)
  • src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java (5 hunks)
Additional comments not posted (30)
src/main/java/taco/klkl/domain/product/dto/request/ProductSortOptionsDto.java (1)

3-6: Appropriate use of Java record for DTO.

The use of a Java record here is a good choice for defining a simple data transfer object with immutable fields. This enhances readability and maintainability.

src/main/java/taco/klkl/domain/product/exception/InvalidSortOptionException.java (1)

6-9: Well-implemented custom exception.

The InvalidSortOptionException correctly extends the CustomException and uses a specific error code. This approach is clean and maintains consistency in exception handling.

src/main/java/taco/klkl/global/common/constants/ProductConstants.java (1)

20-21: Addition of sorting constants is well-structured.

The use of Set.of() for defining ALLOWED_SORT_BY and ALLOWED_SORT_DIRECTION is appropriate, ensuring immutability and clarity. These constants are well-named and support the new sorting feature effectively.

Ensure these constants are utilized correctly throughout the codebase to validate sorting options.

Verification successful

Constants are correctly utilized for sorting validation.

The ALLOWED_SORT_BY and ALLOWED_SORT_DIRECTION constants are appropriately used in ProductService.java to validate sorting options, ensuring only allowed values are used. This confirms their correct implementation and usage in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `ALLOWED_SORT_BY` and `ALLOWED_SORT_DIRECTION` constants.

# Test: Search for the usage of these constants. Expect: Occurrences where sorting options are validated.
rg --type java 'ALLOWED_SORT_BY|ALLOWED_SORT_DIRECTION'

Length of output: 669

src/main/java/taco/klkl/global/error/exception/ErrorCode.java (1)

24-26: Additions look good. Verify usage of INVALID_SORT_OPTION.

The addition of INVALID_SORT_OPTION enhances error handling for sorting. Ensure that this new error code is used appropriately in the application logic.

Verification successful

Usage of INVALID_SORT_OPTION Verified

The INVALID_SORT_OPTION error code is effectively used in the application logic through the InvalidSortOptionException, particularly within the ProductService class. This confirms proper integration for handling invalid sort options.

  • ProductService.java: validateSortOptions method throws InvalidSortOptionException.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new error code `INVALID_SORT_OPTION`.

# Test: Search for the usage of `INVALID_SORT_OPTION`. Expect: Occurrences in the application logic.
rg --type java 'INVALID_SORT_OPTION'

Length of output: 294


Script:

#!/bin/bash
# Description: Search for the usage of `InvalidSortOptionException` in the codebase to verify integration of `INVALID_SORT_OPTION`.

rg --type java 'InvalidSortOptionException'

Length of output: 845

src/main/java/taco/klkl/domain/product/controller/ProductController.java (4)

26-26: Import addition is appropriate.

The import of ProductSortOptionsDto is necessary for handling sorting options.


48-49: New sorting parameters are well-defined.

The addition of sort_by and sort_direction parameters with default values enhances the flexibility of product sorting.


56-60: Construction of ProductSortOptionsDto is correct.

The creation of ProductSortOptionsDto with the sorting parameters is well-implemented.


60-60: Ensure integration with the service layer.

The getProductsByFilterOptions method now includes sorting options. Verify that the service layer correctly handles these options.

Verification successful

Integration with the service layer is correctly implemented.

The getProductsByFilterOptions method in ProductService.java validates and utilizes ProductSortOptionsDto, confirming that sorting options are handled appropriately in the service layer.

  • ProductService.java:
    • Line 74: validateSortOptions(sortOptions);
    • Line 79: fetchProducts(baseQuery, pageable, sortOptions);
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of sorting options in the service layer.

# Test: Search for the `getProductsByFilterOptions` method and check for handling of `ProductSortOptionsDto`.
ast-grep --lang java --pattern $'public $_ getProductsByFilterOptions($_, $_, ProductSortOptionsDto sortOptions) { $$$ }'

Length of output: 122


Script:

#!/bin/bash
# Description: Search for the `getProductsByFilterOptions` method in the codebase without specifying parameter types.

# Test: Search for any occurrence of the `getProductsByFilterOptions` method.
ast-grep --lang java --pattern $'public $_ getProductsByFilterOptions($$$) { $$$ }'

Length of output: 1733

src/main/resources/database/data.sql (1)

132-136: Inclusion of like_count is consistent with new features.

The addition of the like_count column in the Product table aligns with the sorting feature requirements.

src/main/java/taco/klkl/domain/product/service/ProductService.java (6)

75-75: LGTM! Validate sort options before use.

The addition of validateSortOptions ensures that only allowed sort options are used, which is a good practice.


122-139: LGTM! The query construction is well-structured.

The use of helper methods for creating specific filters improves readability and maintainability.


147-159: LGTM! The product fetching logic is clear and effective.

The encapsulation of sorting and pagination logic within this method is well-done, promoting separation of concerns.


162-170: LGTM! Sorting logic is correctly applied.

The use of OrderSpecifier to apply sorting based on direction and field is appropriate and flexible.


261-268: LGTM! Sort options validation is robust.

The method effectively ensures that only allowed sort options are used, which is crucial for maintaining data integrity.


70-79: Ensure correct usage of sortOptions across the codebase.

The addition of ProductSortOptionsDto sortOptions to the method signature is a significant change. Ensure all calls to getProductsByFilterOptions are updated to include this new parameter.

Verification successful

All calls to getProductsByFilterOptions are correctly updated with sortOptions.

The integration of the ProductSortOptionsDto sortOptions parameter in the getProductsByFilterOptions method has been consistently applied across the codebase. This includes updates in the ProductController, ProductServiceTest, and ProductControllerTest files.

  • ProductController.java: Method call correctly includes sortOptions.
  • ProductServiceTest.java: Test cases include sortOptions.
  • ProductControllerTest.java: Mocking and verification include sortOptions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `getProductsByFilterOptions` include the new `sortOptions` parameter.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type java -A 5 $'getProductsByFilterOptions'

Length of output: 3309

src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java (1)

163-194: LGTM! Sorting functionality is well-tested.

The test effectively validates that products can be retrieved with the specified sorting options. Ensure that test coverage includes all possible sorting scenarios.

Verification successful

Comprehensive Test Coverage for Sorting Scenarios

The test coverage for sorting scenarios using ProductSortOptionsDto is comprehensive across both service and controller layers. Ensure that all possible sorting criteria and directions are tested to maintain robust functionality.

  • Files Involved:
    • src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java
    • src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for all sorting scenarios.

# Test: Search for test cases involving `ProductSortOptionsDto`. Expect: Comprehensive coverage of sorting scenarios.
rg --type java -A 5 $'ProductSortOptionsDto'

Length of output: 9956

src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java (1)

Line range hint 136-194:
LGTM! Controller sorting logic is well-tested.

The test ensures that sorting parameters are correctly handled by the controller. Verify that all sorting scenarios are covered in the tests.

src/test/java/taco/klkl/domain/product/integration/ProductIntegrationTest.java (13)

209-210: LGTM! Sorting parameters added correctly.

The addition of sorting parameters sort_by and sort_direction is consistent with the feature objectives.


269-270: LGTM! Sorting parameters added correctly.

The addition of sorting parameters sort_by and sort_direction is consistent with the feature objectives.


343-344: LGTM! Sorting parameters added correctly.

The addition of sorting parameters sort_by and sort_direction is consistent with the feature objectives.


416-417: LGTM! Sorting parameters added correctly.

The addition of sorting parameters sort_by and sort_direction is consistent with the feature objectives.


490-491: LGTM! Sorting parameters added correctly.

The addition of sorting parameters sort_by and sort_direction is consistent with the feature objectives.


563-564: LGTM! Sorting parameters added correctly.

The addition of sorting parameters sort_by and sort_direction is consistent with the feature objectives.


581-654: LGTM! New test for sorting by creation date in ascending order.

The test method is well-structured and effectively validates the sorting functionality.


656-729: LGTM! New test for sorting by creation date in descending order.

The test method is well-structured and effectively validates the sorting functionality.


731-804: LGTM! New test for sorting by rating in ascending order.

The test method is well-structured and effectively validates the sorting functionality.


806-879: LGTM! New test for sorting by rating in descending order.

The test method is well-structured and effectively validates the sorting functionality.


881-902: LGTM! New test for sorting by like count in ascending order.

The test method is well-structured and effectively validates the sorting functionality.


904-925: LGTM! New test for sorting by like count in descending order.

The test method is well-structured and effectively validates the sorting functionality.


154-159: Verify data setup consistency for pagination test.

The expected number of products has been increased from 4 to 5. Ensure that the data setup reflects this change consistently across all related tests.

@ohhamma ohhamma merged commit ea07b33 into KL-71/μƒν’ˆ-λͺ©λ‘-쑰회-api-κ΅¬ν˜„ Aug 15, 2024
2 checks passed
@ohhamma ohhamma deleted the KL-94/μƒν’ˆ-μ •λ ¬-κΈ°λŠ₯ branch August 15, 2024 14:45
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.

1 participant