-
Notifications
You must be signed in to change notification settings - Fork 0
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-68): update Product API #25
The head ref may contain hidden characters: "KL-68/\uC0C1\uD488-\uC815\uBCF4-\uC218\uC815-api-\uAD6C\uD604"
Conversation
- updateDtoλ₯Ό λ°μ nullμ΄ μλ νλ κ°μ λ³κ²½νλ μν update λ©μλ μμ± - κ΄λ ¨ ν μ€νΈμ½λ μμ± - μν μ 보 μ λ°μ΄νΈ ν μ€νΈ - μν μ 보 λΆλΆ μ λ°μ΄νΈ ν μ€νΈ - μν μ 보 μ λ°μ΄νΈ μ null κ° λ¬΄μ ν μ€νΈ
- ProductServiceμ id, updateDtoλ₯Ό λ°μ μνμ μ 보λ₯Ό μμ λ° λ ν¬μ§ν 리μ λ³κ²½μ¬ν μ μ₯ - κ΄λ ¨ ν μ€νΈμ½λ μμ± - μν μ λ°μ΄νΈ μ±κ³΅ ν μ€νΈ - μν μ λ°μ΄νΈ μ€ν¨ ν μ€νΈ - μν μμ
- μν μ 보 μμ API ꡬν - κ΄λ ¨ ν μ€νΈμ½λ μμ± - μν μ 보 λΆλΆ μ λ°μ΄νΈ API ν μ€νΈ
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.
μν μμ±λ€μ μ ν¨μ±κ²μ¬κ° μΆκ°λλ©΄ μ’μκ±° κ°μ΅λλ€!
- μν λ±λ‘ μμ² μ ν¨μ± κ²μ¬ - 컨νΈλ‘€λ¬μ @Valid ν€μλ μΆκ° - κ΄λ ¨ ν μ€νΈμ½λ μΆκ° - μν λ±λ‘ API μ ν¨μ± κ²μ¬ μ€ν¨ ν μ€νΈ - μ ν¨μ± κ²μ¬μμ λ°μν μ€λ₯ λ©μμ§λ₯Ό μμ§ν΄μ μΆλ ₯νλλ‘ GlobalExceptionHandler μμ - μμ λ λ΄μ©μ λ§κ² ν μ€νΈμ½λ μμ - BindingResultλ₯Ό λͺ¨νΉν΄μ getFieldErrors()κ° μ ν¨ν FieldError λͺ©λ‘μ λ°ννλλ‘ μ€μ - h2 λ°μ΄ν°λ² μ΄μ€ λͺ¨λ MySQLλ‘ μ€μ
- μ ν¨νμ§ μμ μμ² λ©μμ§μ λν μμΈ νΈλ€λ§ - κ΄λ ¨ ν μ€νΈμ½λ μΆκ°
- μν κ°κ²©μ΄ 0 μ΄μμ΄μ΄μΌ νλ€λ μ μ½ μΆκ° - κ΄λ ¨ ν μ€νΈμ½λ μΆκ° - κ°κ²©μ΄ μμμΌ λ μ ν¨μ± κ²μ¬ μ€ν¨ - κ°κ²©μ΄ 0μΌ λ μ ν¨μ± κ²μ¬ μ±κ³΅ - μν μμ² dtoμμ κ°κ²©κ³Ό μ£Όμ μ리 λ°κΏ - λ°λ μ리μ λ§κ² κ΄λ ¨ ν μ€νΈμ½λ μμ
- κ° ν μ€νΈμΌμ΄μ€μμ λ°μν μμΈμ λν μ½λμ λ©μμ§λ₯Ό ErrorCodeμ μμΈμ κ°λ€κ³Ό λΉκ΅νλλ‘ μμ - μ§μνμ§ μλ λ©μλ μμΈμ μ΄λ¦μ METHOD_NOT_SUPPORTEDλ‘ λ³κ²½
- μν λ±λ‘ μμ² dtoμ μ ν¨μ± κ²μ¬ μΆκ° - μνλͺ , μν μ€λͺ , μ£Όμμ κΈΈμ΄ κ²μ¬ - νμ String νλμμ λΉ λ¬Έμμ΄ κ²μ¬ - κ°κ²©μ λ²μ κ²μ¬ - μΆκ°λ κ²μ¬ λ΄μ© ν μ€νΈμ½λμ μΆκ° - μν λ±λ‘ μμ² dtoμ νλ μμ λ³κ²½ - μ΄μ λ§κ² ν μ€νΈμ½λ μμ - μν νλμ maxκ° constantsλ‘ κ΄λ¦¬ - μ΄λ¦, μ€λͺ , μ£Όμμ κ° μ΅λ κΈΈμ΄
- μν λ±λ‘ μ ν¨μ± κ²μ¬ μ 보μ¬μ£Όλ λ©μμ§λ€μ μμλ‘ κ΄λ¦¬ - μ΄μ λ§κ² ν μ€νΈμ½λ μμ
- μμ κ΄λ¦¬νλ ν΄λμ€μ final ν€μλ μΆκ°
- μν μ 보 μμ μ μ ν¨μ± κ²μ¬ - μνλͺ , μνμ€λͺ , μ£Όμ κΈΈμ΄ κ²μ¬ - κ°κ²© λ²μ κ²μ¬ - μν μ 보 μμ dto νλ μμ λ³κ²½ - μ΄μ λ°λΌ ν μ€νΈμ½λ μμ
src/main/java/taco/klkl/domain/product/controller/ProductController.java
Show resolved
Hide resolved
src/test/java/taco/klkl/domain/product/dto/request/ProductCreateRequestDtoTest.java
Show resolved
Hide resolved
src/main/java/taco/klkl/global/error/GlobalExceptionHandler.java
Outdated
Show resolved
Hide resolved
- νμ μλ TODO μ½λ©νΈ μμ
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.
μνμ΄ ν κ² λ§μλ° κ³ μνμ
¨μ΅λλ€!
μμ νμ₯λ μ½λ© μ²μ¬μλ€μ :)
- update λ‘μ§μ λΆνμν save λ©μλ νΈμΆ μ κ±° - μ΄μ λ°λ₯Έ ν μ€νΈμ½λ μμ
WalkthroughThis update enhances the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ProductController
participant ProductService
participant ProductRepository
Client->>ProductController: PATCH /products/{id}
ProductController->>ProductService: updateProduct(id, updateRequest)
ProductService->>ProductRepository: findById(id)
ProductRepository-->>ProductService: product
ProductService->>Product: update(updateRequest)
Product->>ProductService: return updated product
ProductService-->>ProductController: return updated product
ProductController-->>Client: ResponseEntity<ProductDetailResponseDto>
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
@coderabbitai review |
Actions performedReview triggered.
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (19)
- 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/ProductCreateRequestDto.java (1 hunks)
- src/main/java/taco/klkl/domain/product/dto/request/ProductUpdateRequestDto.java (1 hunks)
- src/main/java/taco/klkl/domain/product/service/ProductService.java (2 hunks)
- src/main/java/taco/klkl/global/common/constants/DefaultConstants.java (1 hunks)
- src/main/java/taco/klkl/global/common/constants/ProductConstants.java (1 hunks)
- src/main/java/taco/klkl/global/common/constants/ProductValidationMessages.java (1 hunks)
- src/main/java/taco/klkl/global/common/constants/UserConstants.java (1 hunks)
- src/main/java/taco/klkl/global/error/GlobalExceptionHandler.java (5 hunks)
- src/main/java/taco/klkl/global/error/exception/ErrorCode.java (1 hunks)
- src/main/resources/application-h2.yaml (1 hunks)
- src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java (6 hunks)
- src/test/java/taco/klkl/domain/product/domain/ProductTest.java (3 hunks)
- src/test/java/taco/klkl/domain/product/dto/request/ProductCreateRequestDtoTest.java (2 hunks)
- src/test/java/taco/klkl/domain/product/dto/request/ProductUpdateRequestDtoTest.java (2 hunks)
- src/test/java/taco/klkl/domain/product/integration/ProductIntegrationTest.java (2 hunks)
- src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java (3 hunks)
- src/test/java/taco/klkl/global/error/GlobalExceptionHandlerTest.java (7 hunks)
Files skipped from review due to trivial changes (1)
- src/main/java/taco/klkl/global/common/constants/DefaultConstants.java
Additional comments not posted (57)
src/main/java/taco/klkl/global/common/constants/ProductConstants.java (2)
3-3
: Good practice: Making the class final.Declaring the class as
final
prevents it from being subclassed, which is a good practice for utility classes.
9-11
: New constants added for validation.The new constants
NAME_MAX_LENGTH
,DESCRIPTION_MAX_LENGTH
, andADDRESS_MAX_LENGTH
provide clear guidelines for data validation.src/main/java/taco/klkl/global/common/constants/UserConstants.java (1)
6-6
: Good practice: Making the class final.Declaring the class as
final
prevents it from being subclassed, which is a good practice for utility classes.src/main/resources/application-h2.yaml (1)
10-10
: Verify the impact ofMODE=MySQL
.The change introduces compatibility with MySQL syntax. Ensure that all SQL queries are compatible with MySQL mode and test thoroughly.
src/main/java/taco/klkl/domain/product/dto/request/ProductUpdateRequestDto.java (2)
3-6
: LGTM!The import statements are correct and necessary for the validation annotations and constants used in the record.
9-26
: LGTM!The validation annotations ensure data integrity by enforcing size and positivity constraints. The usage of constants for validation messages and sizes promotes maintainability.
src/main/java/taco/klkl/global/error/exception/ErrorCode.java (1)
13-15
: LGTM!The renaming of
METHOD_NOT_ALLOWED
toMETHOD_NOT_SUPPORTED
improves clarity. The addition ofHTTP_MESSAGE_NOT_READABLE
enhances error handling for invalid request message formats.src/main/java/taco/klkl/global/common/constants/ProductValidationMessages.java (1)
1-23
: LGTM!The validation messages are clear and provide specific feedback for each field. The class is well-structured and final, preventing inheritance.
src/main/java/taco/klkl/domain/product/dto/request/ProductCreateRequestDto.java (8)
3-8
: LGTM! Imports are necessary for the new validation annotations and constants.The added import statements are appropriate and necessary for the new validation annotations and constants.
22-25
: LGTM! Validation annotations for thename
field are appropriate.The
@NotNull
,@NotBlank
, and@Size
annotations ensure that thename
field is not null, not blank, and within the specified size limit.
27-30
: LGTM! Validation annotations for thedescription
field are appropriate.The
@NotNull
,@NotBlank
, and@Size
annotations ensure that thedescription
field is not null, not blank, and within the specified size limit.
32-33
: LGTM! Validation annotation for theaddress
field is appropriate.The
@Size
annotation ensures that theaddress
field is within the specified size limit.
35-36
: LGTM! Validation annotation for theprice
field is appropriate.The
@PositiveOrZero
annotation ensures that theprice
field is non-negative.
38-39
: LGTM! Validation annotation for thecityId
field is appropriate.The
@NotNull
annotation ensures that thecityId
field is not null.
41-42
: LGTM! Validation annotation for thesubcategoryId
field is appropriate.The
@NotNull
annotation ensures that thesubcategoryId
field is not null.
44-45
: LGTM! Validation annotation for thecurrencyId
field is appropriate.The
@NotNull
annotation ensures that thecurrencyId
field is not null.src/main/java/taco/klkl/domain/product/service/ProductService.java (4)
10-14
: LGTM! Imports are necessary for the new methods and functionality.The added import statements are appropriate and necessary for the new methods and functionality.
25-26
: LGTM! Use offinal
keyword enhances code clarity and immutability.The
final
keyword for the parameter and the local variable ensures that these values are not modified, enhancing code clarity and immutability.
31-34
: LGTM!createProduct
method is appropriate for creating new products.The
@Transactional
annotation ensures that the method performs write operations within a transaction.
38-43
: LGTM!updateProduct
method is appropriate for updating existing products.The
@Transactional
annotation ensures that the method performs write operations within a transaction.src/main/java/taco/klkl/domain/product/controller/ProductController.java (3)
Line range hint
6-18
:
LGTM! Imports are necessary for the new endpoint and enhanced validation.The added import statements are appropriate and necessary for the new endpoint and enhanced validation.
39-41
: LGTM!@Valid
annotation enhances validation for thecreateProduct
method.The
@Valid
annotation ensures that the incoming product creation requests are validated according to the constraints defined in the DTO.
46-54
: LGTM!updateProduct
method is appropriate for updating product information.The
@Valid
annotation ensures that the input is validated according to the constraints defined in the DTO.src/test/java/taco/klkl/domain/product/integration/ProductIntegrationTest.java (2)
45-49
: Verify the new parameters inProductCreateRequestDto
.Ensure that the new parameters ("address" and 1000) align with the expected input format for product creation.
78-82
: Verify the new parameters inProductCreateRequestDto
.Ensure that the new parameters ("address" and 1000) align with the expected input format for product creation.
src/main/java/taco/klkl/domain/product/domain/Product.java (2)
39-94
: LGTM! Improved maintainability and readability.The use of constants from
ProductConstants
andDefaultConstants
enhances maintainability and readability.
142-164
: LGTM! New method for selective updates.The new method
update
correctly updates the product properties based on theProductUpdateRequestDto
.src/test/java/taco/klkl/domain/product/dto/request/ProductUpdateRequestDtoTest.java (5)
30-39
: LGTM! Clearer method naming.The method
validProductUpdateRequestDto
provides a clearer description of its purpose and correctly validates aProductUpdateRequestDto
with all valid fields.
46-65
: LGTM! Enhanced validation for product name length.The new parameterized test
productNameExceedsMaxLength
correctly validates the maximum length constraint for the product name and provides meaningful error messages.
67-86
: LGTM! Enhanced validation for product description length.The new parameterized test
productDescriptionExceedsMaxLength
correctly validates the maximum length constraint for the product description and provides meaningful error messages.
88-107
: LGTM! Enhanced validation for address length.The new parameterized test
addressExceedsMaxLength
correctly validates the maximum length constraint for the address and provides meaningful error messages.
109-126
: LGTM! Enhanced validation for non-negative price.The new parameterized test
negativePrice
correctly validates that the price cannot be negative and provides meaningful error messages.src/main/java/taco/klkl/global/error/GlobalExceptionHandler.java (4)
Line range hint
27-50
: LGTM! Improved error reporting for method argument validation.The changes enhance the clarity of the error responses by collecting all field errors and constructing a comprehensive error message.
Line range hint
62-66
: LGTM! Corrected error code for HTTP method not supported.The change aligns the error handling with more accurate HTTP semantics.
83-95
: LGTM! Added structured error handling for unreadable HTTP messages.The new method provides consistent and informative feedback for
HttpMessageNotReadableException
.
Line range hint
96-104
: LGTM! Structured error handling for custom exceptions.The method provides consistent and informative feedback for
CustomException
.src/test/java/taco/klkl/domain/product/domain/ProductTest.java (4)
Line range hint
80-104
: LGTM! Updated display name for price handling.The change aligns the display name with the intended data type for price handling.
107-142
: LGTM! Comprehensive test for updating product information.The test ensures that all product attributes are correctly updated when provided with a complete
ProductUpdateRequestDto
.
144-179
: LGTM! Test for partial update of product information.The test ensures that the product retains its original values for any attributes that are not included in the update request, while still updating the fields that are provided.
181-215
: LGTM! Test for ignoring null values during product update.The test ensures that when all fields in the update DTO are
null
, the product remains unchanged.src/test/java/taco/klkl/domain/product/service/ProductServiceTest.java (2)
157-200
: LGTM! Test for successful product update.The test sets up a mock product repository to return an existing product when queried by its ID and verifies that the update logic functions correctly.
202-227
: LGTM! Test for product update failure when product not found.The test verifies that a
ProductNotFoundException
is thrown when the product ID is not found in the repository.src/test/java/taco/klkl/global/error/GlobalExceptionHandlerTest.java (1)
120-143
: LGTM!The new test method
httpMessageNotReadableOccurred
is correctly implemented and ensures that theHttpMessageNotReadableException
is handled as expected.src/test/java/taco/klkl/domain/product/dto/request/ProductCreateRequestDtoTest.java (10)
30-42
: LGTM!The test method
validProductCreateRequestDto
is correctly implemented and verifies that a validProductCreateRequestDto
passes validation.
47-64
: LGTM!The test method
nullProductName
is correctly implemented and verifies that aProductCreateRequestDto
with a null product name fails validation with the appropriate message.
68-86
: LGTM!The test method
emptyProductName
is correctly implemented and verifies that aProductCreateRequestDto
with an empty product name fails validation with the appropriate message.
88-105
: LGTM!The parameterized test method
productNameExceedsMaxLength
is correctly implemented and verifies that aProductCreateRequestDto
with a product name that exceeds the maximum length fails validation with the appropriate message.
109-126
: LGTM!The test method
nullProductDescription
is correctly implemented and verifies that aProductCreateRequestDto
with a null product description fails validation with the appropriate message.
130-148
: LGTM!The test method
emptyProductDescription
is correctly implemented and verifies that aProductCreateRequestDto
with an empty product description fails validation with the appropriate message.
150-167
: LGTM!The parameterized test method
productDescriptionExceedsMaxLength
is correctly implemented and verifies that aProductCreateRequestDto
with a product description that exceeds the maximum length fails validation with the appropriate message.
170-188
: LGTM!The parameterized test method
addressExceedsMaxLength
is correctly implemented and verifies that aProductCreateRequestDto
with an address that exceeds the maximum length fails validation with the appropriate message.
190-206
: LGTM!The parameterized test method
negativePrice
is correctly implemented and verifies that aProductCreateRequestDto
with a negative price fails validation with the appropriate message.
210-260
: LGTM!The test methods
nullCityId
,nullSubcategoryId
, andnullCurrencyId
are correctly implemented and verify that aProductCreateRequestDto
with null values for cityId, subcategoryId, and currencyId, respectively, fail validation with the appropriate messages.src/test/java/taco/klkl/domain/product/controller/ProductControllerTest.java (4)
Line range hint
5-29
:
LGTM!The new imports for
ProductUpdateRequestDto
andeq
matcher are correctly added. The setup method initializes mock objects forUser
andProduct
appropriately.
98-106
: LGTM!The test method
testCreateProduct
is correctly implemented and verifies that the product creation endpoint works as expected with valid data.
129-154
: LGTM!The test method
testCreateProductValidationFailure
is correctly implemented and verifies that the product creation endpoint returns the appropriate validation errors for invalid data.
156-192
: LGTM!The test method
testUpdateProduct
is correctly implemented and verifies that the product update endpoint works as expected with valid data.
src/main/java/taco/klkl/global/common/constants/ProductValidationMessages.java
Show resolved
Hide resolved
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.
JpaRepositoryκ° μν°ν° κ°μ²΄μ λ³κ²½μ κ°μ§νκ³ λͺ
μμ μΈ save()νΈμΆ μμ΄ dbμ μ©κ°λ₯ν μ μ μ μ μμμ΅λλ€!
κ³ μνμ
¨μ΅λλ€! :)
π μ°κ΄λ μ΄μ
π μμ λ΄μ©
π³ μμ λΈλμΉλͺ
KL-68/μν-μ 보-μμ -api-ꡬν
πΈ μ€ν¬λ¦°μ· (μ ν)
π¬ 리뷰 μꡬμ¬ν (μ ν)
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation