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

refactor(KL-130): change Product update http method #34

Conversation

ohhamma
Copy link
Contributor

@ohhamma ohhamma commented Aug 5, 2024

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

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

  • μƒν’ˆ 정보 μˆ˜μ • apiμ—μ„œ http λ©”μ†Œλ“œ PUT을 μ‚¬μš©ν•˜λ„λ‘ μˆ˜μ •
  • μš”μ²­ dto ν•˜λ‚˜λ‘œ 톡일
  • μƒν’ˆμ˜ pk ν•„λ“œ 이름 productIdμ—μ„œ id둜 λ³€κ²½

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

  • KL-130/μƒν’ˆ-정보-μˆ˜μ •-둜직-λ³€κ²½

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

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

Summary by CodeRabbit

  • New Features

    • Unified the product creation and update request data structure into a single ProductCreateUpdateRequestDto.
    • Changed the HTTP method for updating products from PATCH to PUT for clearer RESTful semantics.
  • Bug Fixes

    • Enhanced data integrity by enforcing mandatory relationships in the product data model.
    • Improved error handling by explicitly declaring exceptions in product retrieval and update methods.
  • Tests

    • Updated tests to reflect the consolidated request DTO for product creation and updates.
    • Adjusted test methods to use the new ID retrieval method for products.

ohhamma added 2 commits August 5, 2024 18:44
- μƒν’ˆ 정보 μˆ˜μ • μ‹œ patch λŒ€μ‹  put λ©”μ†Œλ“œ μ‚¬μš©
- μš”μ²­ dtoλ₯Ό ProductCreateUpdateRequestDto둜 톡일
- μƒν’ˆ ν•„λ“œμ— nullable, optional λͺ…μ‹œμ μœΌλ‘œ μΆ”κ°€
- μƒν’ˆ serviceμ—μ„œ λ°˜ν™˜ν•˜λŠ” μ˜ˆμ™Έ λͺ…μ‹œμ μœΌλ‘œ μž‘μ„±
- μƒν’ˆ pk ν•„λ“œ productIdμ—μ„œ id둜 μˆ˜μ •
@ohhamma ohhamma added the ♻️ Refactor μ½”λ“œ λ¦¬νŒ©ν† λ§ label Aug 5, 2024
@ohhamma ohhamma requested review from idealflower-k and min3m August 5, 2024 10:29
@ohhamma ohhamma self-assigned this Aug 5, 2024
Copy link

coderabbitai bot commented Aug 5, 2024

Walkthrough

The recent changes streamline the product management functionality within the application by consolidating the data transfer objects for product creation and updates into a single ProductCreateUpdateRequestDto. This unification simplifies the request handling and enhances code maintainability. Additionally, the product controller now correctly uses HTTP PUT for updates, aligning with RESTful principles, while adjustments to the Product class enforce mandatory relationships, improving data integrity.

Changes

File Change Summary
src/main/java/taco/klkl/domain/product/controller/ProductController.java Consolidated ProductCreateRequestDto and ProductUpdateRequestDto into ProductCreateUpdateRequestDto; changed update method to use @PutMapping.
src/main/java/taco/klkl/domain/product/domain/Product.java Renamed productId to id; updated relations to @ManyToOne(optional = false) to enforce integrity; streamlined update method logic.
src/main/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDto.java Renamed DTO to reflect combined functionality for creation and updating.
src/main/java/taco/klkl/domain/product/service/ProductService.java Updated methods to use new DTO; added throws declarations for exceptions; revised retrieval methods for specificity.
src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java Updated tests to use the new consolidated DTO and HTTP method changes.
src/test/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDtoTest.java Updated references to the new consolidated DTO.
src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java Adjusted imports and method calls to the new DTO structure.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProductController
    participant ProductService
    participant ProductRepository

    Client->>ProductController: Create/Update Product Request
    ProductController->>ProductService: createProduct(createRequest)
    ProductService->>ProductRepository: save(product)
    ProductRepository-->>ProductService: Product saved
    ProductService-->>ProductController: Return Product Detail
    ProductController-->>Client: Return Response
Loading

Assessment against linked issues

Objective Addressed Explanation
Modify product update logic (KL-130) βœ…
Ensure data integrity in product relationships βœ…
Streamline request handling for product operations βœ…

Poem

πŸ‡ In the code where rabbits hop,
Products change and never stop.
With updates neat and data tight,
We leap with joy, all feels right!
Consolidated, clear, and bright,
A perfect path to code delight! 🌼


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 5, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Aug 5, 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

Outside diff range, codebase verification and nitpick comments (1)
src/main/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDto.java (1)

21-21: Update method name for consistency

The method name testValidProductCreateRequestDto in ProductCreateUpdateRequestDtoTest.java should be updated to testValidProductCreateUpdateRequestDto for consistency with the new record name.

  • src/test/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDtoTest.java: Update method name testValidProductCreateRequestDto to testValidProductCreateUpdateRequestDto.
Analysis chain

LGTM! Ensure consistency across the codebase.

The change from ProductCreateRequestDto to ProductCreateUpdateRequestDto is approved.

Verify that all instances of ProductCreateRequestDto have been updated to ProductCreateUpdateRequestDto across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `ProductCreateRequestDto` have been updated to `ProductCreateUpdateRequestDto`.

# Test: Search for the old record name usage. Expect: No occurrences of `ProductCreateRequestDto`.
rg --type java 'ProductCreateRequestDto'

Length of output: 173


Script:

#!/bin/bash
# Description: Check the context of the occurrence of `ProductCreateRequestDto` in the test file.

# Search for the old record name usage with context lines to understand its usage.
rg --type java 'ProductCreateRequestDto' -A 5 -B 5

Length of output: 1359

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6e1eae and 6a6e004.

Files selected for processing (13)
  • src/main/java/taco/klkl/domain/product/controller/ProductController.java (3 hunks)
  • src/main/java/taco/klkl/domain/product/domain/Product.java (3 hunks)
  • src/main/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDto.java (1 hunks)
  • src/main/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDto.java (1 hunks)
  • src/main/java/taco/klkl/domain/product/dto/response/ProductSimpleResponseDto.java (1 hunks)
  • src/main/java/taco/klkl/domain/product/service/ProductService.java (3 hunks)
  • src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java (8 hunks)
  • src/test/java/taco/klkl/domain/product/domain/ProductTest.java (1 hunks)
  • src/test/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDtoTest.java (27 hunks)
  • src/test/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDtoTest.java (1 hunks)
  • src/test/java/taco/klkl/domain/product/dto/response/ProductSimpleResponseDtoTest.java (1 hunks)
  • src/test/java/taco/klkl/domain/product/integration/ProductIntegrationTest.java (12 hunks)
  • src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java (8 hunks)
Files skipped from review due to trivial changes (1)
  • src/test/java/taco/klkl/domain/product/domain/ProductTest.java
Additional comments not posted (53)
src/main/java/taco/klkl/domain/product/dto/response/ProductSimpleResponseDto.java (1)

24-24: LGTM! Ensure consistency across the codebase.

The change from product.getProductId() to product.getId() is approved.

Verify that all instances of product.getProductId() have been updated to product.getId() across the codebase.

Verification successful

Verification successful.

The update from product.getProductId() to product.getId() has been consistently applied across the codebase.

  • Instances of product.getId() found in:
    • src/test/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDtoTest.java
    • src/main/java/taco/klkl/domain/product/dto/response/ProductSimpleResponseDto.java
    • src/main/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDto.java
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `product.getProductId()` have been updated to `product.getId()`.

# Test: Search for the old method usage. Expect: No occurrences of `product.getProductId()`.
rg --type java 'product.getProductId()'

Length of output: 41


Script:

#!/bin/bash
# Description: Verify all instances of `product.getProductId()` have been updated to `product.getId()`.

# Search for the old method usage. Expect: No occurrences of `product.getProductId()`.
rg --type java 'product.getProductId()'

# Search for the new method usage to ensure it is being used correctly.
rg --type java 'product.getId()'

Length of output: 413

src/main/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDto.java (1)

38-38: LGTM! Ensure consistency across the codebase.

The change from product.getProductId() to product.getId() is approved.

Verify that all instances of product.getProductId() have been updated to product.getId() across the codebase.

Verification successful

Verification successful.

The transition from product.getProductId() to product.getId() has been consistently applied across the codebase.

  • src/test/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDtoTest.java
  • src/main/java/taco/klkl/domain/product/dto/response/ProductSimpleResponseDto.java
  • src/main/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDto.java
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `product.getProductId()` have been updated to `product.getId()`.

# Test: Search for the old method usage. Expect: No occurrences of `product.getProductId()`.
rg --type java 'product.getProductId()'

Length of output: 41


Script:

#!/bin/bash
# Description: Verify all instances of `product.getId()` to ensure the transition from `product.getProductId()` was made correctly.

# Test: Search for the new method usage. Expect: Multiple occurrences of `product.getId()`.
rg --type java 'product.getId()'

Length of output: 371

src/test/java/taco/klkl/domain/product/dto/response/ProductSimpleResponseDtoTest.java (1)

25-25: LGTM!

The change from getProductId() to getId() aligns with the refactoring of the Product class. The test logic remains correct.

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

13-13: LGTM!

The import of PutMapping is necessary for the updated HTTP method in the controller.


24-24: LGTM!

The import of ProductCreateUpdateRequestDto is necessary for the consolidated DTO used in the controller methods.


60-60: LGTM!

Updating the parameter type to ProductCreateUpdateRequestDto consolidates the request data structure, simplifying the code and improving maintainability.


65-65: LGTM!

Changing the HTTP method to PUT aligns with RESTful principles. Updating the parameter type to ProductCreateUpdateRequestDto consolidates the request data structure, simplifying the code and improving maintainability.

Also applies to: 69-69

src/test/java/taco/klkl/domain/product/dto/response/ProductDetailResponseDtoTest.java (1)

35-35: LGTM!

The change from getProductId() to getId() aligns with the refactoring of the Product class. The test logic remains correct.

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

35-35: LGTM! Simplified identifier naming.

The renaming of productId to id simplifies the identifier naming convention.


37-41: LGTM! Enforced non-null constraint for user association.

The @ManyToOne(optional = false) and @JoinColumn(nullable = false) annotations enforce that a Product cannot exist without a corresponding User, improving data integrity.


87-91: LGTM! Enforced non-null constraint for city association.

The @ManyToOne(optional = false) and @JoinColumn(nullable = false) annotations enforce that a Product cannot exist without a corresponding City, improving data integrity.


94-98: LGTM! Enforced non-null constraint for subcategory association.

The @ManyToOne(optional = false) and @JoinColumn(nullable = false) annotations enforce that a Product cannot exist without a corresponding Subcategory, improving data integrity.


101-105: LGTM! Enforced non-null constraint for currency association.

The @ManyToOne(optional = false) and @JoinColumn(nullable = false) annotations enforce that a Product cannot exist without a corresponding Currency, improving data integrity.


162-168: LGTM! Simplified update method.

The update method has been streamlined by removing conditional checks for null values and directly assigning parameters to fields, simplifying the method and reducing boilerplate code.

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

47-47: LGTM! Improved error handling in getProductById method.

The getProductById method now explicitly declares that it can throw a ProductNotFoundException, improving error handling transparency.


54-55: LGTM! Consolidated request DTOs in createProduct method.

The createProduct method now uses ProductCreateUpdateRequestDto, reducing redundancy and simplifying the method signature.


61-65: LGTM! Consolidated request DTOs and improved error handling in updateProduct method.

The updateProduct method now uses ProductCreateUpdateRequestDto and explicitly declares that it can throw a ProductNotFoundException, improving error handling transparency.


76-92: LGTM! Consolidated request DTOs in createProductEntity method.

The createProductEntity method now uses ProductCreateUpdateRequestDto, reducing redundancy and simplifying the method signature.


94-108: LGTM! Encapsulated update logic in updateProductEntity method.

The updateProductEntity method encapsulates the logic for updating a product, enhancing code organization and readability.


110-111: LGTM! Improved error handling in getCityEntity method.

The getCityEntity method now explicitly declares that it can throw a CityNotFoundException, improving robustness by enforcing error handling.


114-115: LGTM! Improved error handling in getSubcategoryEntity method.

The getSubcategoryEntity method now explicitly declares that it can throw a SubcategoryNotFoundException, improving robustness by enforcing error handling.


118-119: LGTM! Improved error handling in getCurrencyEntity method.

The getCurrencyEntity method now explicitly declares that it can throw a CurrencyNotFoundException, improving robustness by enforcing error handling.

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

27-27: LGTM! Consolidated request DTO imports.

The import statements have been updated to use ProductCreateUpdateRequestDto, reducing redundancy.


27-27: LGTM! Consolidated request DTO imports.

The import statements have been updated to use ProductCreateUpdateRequestDto, reducing redundancy.


82-82: LGTM! Updated mock product ID retrieval.

The setUp method now retrieves the mock product's ID using getId() instead of getProductId(), reflecting the updated method signature of the Product class.


109-109: LGTM! Updated assertion in testGetAllProducts method.

The testGetAllProducts method now validates against the updated method signature, ensuring that the test remains valid and functional after the refactor.


124-124: LGTM! Updated assertion in testGetProductById method.

The testGetProductById method now validates against the updated method signature, ensuring that the test remains valid and functional after the refactor.


Line range hint 143-158:
LGTM! Updated testCreateProduct method.

The testCreateProduct method now uses ProductCreateUpdateRequestDto, streamlining the creation process and ensuring consistency in method calls.


Line range hint 179-201:
LGTM! Updated testUpdateProduct method.

The testUpdateProduct method now uses ProductCreateUpdateRequestDto, streamlining the update process and ensuring consistency in method calls.

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

19-19: Import statement for ProductCreateUpdateRequestDto is correct.

The import statement is necessary for the usage of the consolidated DTO in the tests.


Line range hint 42-51: Correct usage of ProductCreateUpdateRequestDto in testGetProductById.

The method correctly uses the consolidated DTO to create and retrieve a product.


Line range hint 75-100: Correct usage of ProductCreateUpdateRequestDto in testCreateProduct.

The method correctly uses the consolidated DTO to create a product.


Line range hint 108-137: Correct usage of ProductCreateUpdateRequestDto in testGetAllProducts.

The method correctly uses the consolidated DTO to create and retrieve multiple products.


Line range hint 145-167: Correct usage of ProductCreateUpdateRequestDto and HTTP PUT in testUpdateProduct.

The method correctly uses the consolidated DTO and aligns with RESTful principles by using PUT for updates.


Line range hint 188-197: Correct usage of ProductCreateUpdateRequestDto in testDeleteProduct.

The method correctly uses the consolidated DTO to create and delete a product.

src/test/java/taco/klkl/domain/product/dto/request/ProductCreateUpdateRequestDtoTest.java (11)

20-20: Class name update to ProductCreateUpdateRequestDtoTest is correct.

The class name update is necessary to reflect the new DTO name.


Line range hint 31-43: Correct update to test ProductCreateUpdateRequestDto in testValidProductCreateRequestDto.

The method correctly tests the validation of the consolidated DTO.


Line range hint 50-60: Correct update to test ProductCreateUpdateRequestDto in testNullProductName.

The method correctly tests the validation of the consolidated DTO.


Line range hint 71-81: Correct update to test ProductCreateUpdateRequestDto in testEmptyProductName.

The method correctly tests the validation of the consolidated DTO.


Line range hint 94-104: Correct update to test ProductCreateUpdateRequestDto in testProductNameOverMaxLength.

The method correctly tests the validation of the consolidated DTO.


Line range hint 112-122: Correct update to test ProductCreateUpdateRequestDto in testNullProductDescription.

The method correctly tests the validation of the consolidated DTO.


Line range hint 133-143: Correct update to test ProductCreateUpdateRequestDto in testEmptyProductDescription.

The method correctly tests the validation of the consolidated DTO.


Line range hint 156-166: Correct update to test ProductCreateUpdateRequestDto in testProductDescriptionOverMaxLength.

The method correctly tests the validation of the consolidated DTO.


Line range hint 174-184: Correct update to test ProductCreateUpdateRequestDto in testNullAddress.

The method correctly tests the validation of the consolidated DTO.


Line range hint 195-205: Correct update to test ProductCreateUpdateRequestDto in testEmptyAddress.

The method correctly tests the validation of the consolidated DTO.


Line range hint 214-224: Correct update to test ProductCreateUpdateRequestDto in testAddressUnderMaxLength.

The method correctly tests the validation of the consolidated DTO.

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

28-28: Import statement for ProductCreateUpdateRequestDto is correct.

The import statement is necessary for the usage of the consolidated DTO in the tests.


Line range hint 174-204: Correct usage of ProductCreateUpdateRequestDto in testCreateProduct.

The method correctly uses the consolidated DTO to create a product.


Line range hint 212-244: Correct usage of ProductCreateUpdateRequestDto and HTTP PUT in testUpdateProduct.

The method correctly uses the consolidated DTO and aligns with RESTful principles by using PUT for updates.


Line range hint 48-48: No changes related to DTO consolidation or HTTP method update.

The method retrieves all products with default paging.


82-82: No changes related to DTO consolidation or HTTP method update.

The method retrieves all products with custom paging.


Line range hint 116-116: No changes related to DTO consolidation or HTTP method update.

The method retrieves a product by its ID.


Line range hint 251-251: No changes related to DTO consolidation or HTTP method update.

The method deletes a product by its ID.

@ohhamma ohhamma merged commit 9fe7c75 into KL-71/μƒν’ˆ-λͺ©λ‘-쑰회-api-κ΅¬ν˜„ Aug 5, 2024
2 checks passed
@ohhamma ohhamma deleted the KL-130/μƒν’ˆ-정보-μˆ˜μ •-둜직-λ³€κ²½ branch August 5, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️ Refactor μ½”λ“œ λ¦¬νŒ©ν† λ§
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant