-
Notifications
You must be signed in to change notification settings - Fork 0
[REFACTOR] 장바구니 조회 기능 개선 #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cc27026
refactor: CartItem 엔티티에서 User, Product 연관관계 제거 후 ID 기반 매핑으로 단순화 #35
codrin2 44cfa15
refactor: CartItemRepository에서 불필요한 EntityGraph 제거 #35
codrin2 d2f6cda
refactor: CartService에서 User, Product 조회 로직 제거 및 ID 기반 생성으로 단순화 #35
codrin2 ad5b092
feat: Jackson Deserializer 추가 — 문자열 ID를 Long/String으로 변환 #35
codrin2 639759a
refactor: id 타입 변환 로직 제거 #35
codrin2 438e728
refactor: 장바구니 아이템 추가 로직 리팩토링 #35
codrin2 4d0ce43
refactor: 코드 리뷰 반영 #35
codrin2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 24 additions & 4 deletions
28
src/main/kotlin/com/dh/baro/cart/application/CartFacade.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/dh/baro/cart/application/CartItemBundle.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.dh.baro.cart.application | ||
|
|
||
| import com.dh.baro.cart.domain.CartItem | ||
| import com.dh.baro.product.domain.Product | ||
|
|
||
| data class CartItemBundle( | ||
| val cartItem: CartItem, | ||
| val product: Product, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/main/kotlin/com/dh/baro/cart/domain/CartItemRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/com/dh/baro/cart/presentation/dto/AddItemRequest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| package com.dh.baro.cart.presentation.dto | ||
|
|
||
| import jakarta.validation.constraints.Min | ||
| import jakarta.validation.constraints.NotBlank | ||
| import jakarta.validation.constraints.NotNull | ||
|
|
||
| data class AddItemRequest( | ||
| @field:NotBlank(message = "상품 ID를 입력해주세요.") | ||
| val productId: String, | ||
| @field:NotNull(message = "상품 ID를 입력해주세요.") | ||
| val productId: Long, | ||
| @field:Min(value = 1, message = "수량은 1개 이상이어야 합니다.") | ||
| val quantity: Int, | ||
| ) |
34 changes: 31 additions & 3 deletions
34
src/main/kotlin/com/dh/baro/cart/presentation/dto/CartItemResponse.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,41 @@ | ||
| package com.dh.baro.cart.presentation.dto | ||
|
|
||
| import com.dh.baro.cart.application.CartItemBundle | ||
| import com.dh.baro.core.LongToStringSerializer | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize | ||
| import java.math.BigDecimal | ||
| import java.math.RoundingMode | ||
|
|
||
| data class CartItemResponse( | ||
| val itemId: String, | ||
| val productId: String, | ||
| @JsonSerialize(using = LongToStringSerializer::class) | ||
| val itemId: Long, | ||
| @JsonSerialize(using = LongToStringSerializer::class) | ||
| val productId: Long, | ||
| val productName: String, | ||
| val productThumbnailUrl: String?, | ||
| val price: BigDecimal, | ||
| val quantity: Int, | ||
| val subtotal: BigDecimal, | ||
| ) | ||
| ) { | ||
|
|
||
| companion object { | ||
| private const val SCALE_NONE = 0 | ||
|
|
||
| fun from(bundle: CartItemBundle): CartItemResponse { | ||
| val cartItem = bundle.cartItem | ||
| val product = bundle.product | ||
|
|
||
| return CartItemResponse( | ||
| itemId = cartItem.id, | ||
| productId = product.id, | ||
| productName = product.getName(), | ||
| productThumbnailUrl = product.getThumbnailUrl(), | ||
| price = product.getPrice(), | ||
| quantity = cartItem.quantity, | ||
| subtotal = product.getPrice() | ||
| .multiply(BigDecimal(cartItem.quantity)) | ||
| .setScale(SCALE_NONE, RoundingMode.HALF_UP) | ||
| ) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| package com.dh.baro.core | ||
|
|
||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize | ||
|
|
||
| class Cursor ( | ||
| val id: String, | ||
| @JsonSerialize(using = LongToStringSerializer::class) | ||
| val id: Long, | ||
| ) |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/dh/baro/core/LongToStringSerializer.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.dh.baro.core | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator | ||
| import com.fasterxml.jackson.databind.JsonSerializer | ||
| import com.fasterxml.jackson.databind.SerializerProvider | ||
|
|
||
| class LongToStringSerializer : JsonSerializer<Long>() { | ||
| override fun serialize(value: Long?, gen: JsonGenerator, serializers: SerializerProvider) { | ||
| if (value != null) { | ||
| gen.writeString(value.toString()) | ||
| } else { | ||
| gen.writeNull() | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
장바구니 최대 개수 정책, 동시성에 취약.
count→insert 사이 창(window)로 초과 삽입이 가능합니다. 사용자별 아이템 행을 비관적 락으로 선점하거나(예: findByUserId with PESSIMISTIC_WRITE) DB 측에서 보장(별도 집계/트리거, 제한 컬럼)하는 방식을 검토하세요.
원치 않으면 최소한 limit 체크를 "신규 생성 시도 직후" 재검증하는 방어 로직을 추가하세요.
🤖 Prompt for AI Agents