-
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
feature: 봉달 목록 조회 api #38
The head ref may contain hidden characters: "28-feature-\uBD09\uB2EC-\uBAA9\uB85D-\uC870\uD68C-api"
Conversation
id = 1L 인 경우, EntityManger에 의해 동일한 Entity로 판별하여 insert가 되지 않고 update됨
2802e9b
to
cae10d1
Compare
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.
정 성 테 스 트 멋 져 요
src/main/kotlin/com/petqua/application/cart/CartProductService.kt
Outdated
Show resolved
Hide resolved
fun fromDeletedProduct(cartProduct: CartProduct): CartProductResponse { | ||
return CartProductResponse( | ||
id = cartProduct.id, | ||
storeName = "", | ||
productId = cartProduct.productId, | ||
productName = "", | ||
productThumbnailUrl = "", | ||
productPrice = 0, | ||
productDiscountRate = 0, | ||
productDiscountPrice = 0, | ||
quantity = cartProduct.quantity.value, | ||
isMale = cartProduct.isMale, | ||
deliveryMethod = cartProduct.deliveryMethod.name, | ||
isOnSale = false, | ||
) | ||
} |
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.
이 경우에는 [품절]로 표기 하신다고 했어요!
client 입장에서 봉달 목록 data를 한번에 조회하게 되는데 품절인 상품과 그렇지 않은 상품의 응답 스키마가 달라지면 복잡해질 것 같더라고요.
그래서 그냥 임의 데이터로 채워 넣고 isOnSale
로 품절 여부를 판단할 수 있게 두었습니다!
@Transactional(readOnly = true) | ||
fun readAll(memberId: Long): List<CartProductResponse> { | ||
memberRepository.existByIdOrThrow(memberId, MemberException(NOT_FOUND_MEMBER)) | ||
val cartProducts = cartProductRepository.findAllByMemberId(memberId) |
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.
헛 저 찜 목록 조회할 때 이거까지 한 번에 조인해서 가져오게했는데, 혹시 cartProducts를 미리 조회해오신 이유가 있으신가요?
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.
Product가 제거된 cartProduct가 조회 되지 않을 것 같아서 분리했었습니다.
근데 outer join 하고 product가 null인 걸로 삭제 판단해도 될 것 같네요!
커넥션을 줄이는 방향으로 수정해보겠습니다!
productRepository.deleteById(productAId) | ||
val results = cartProductService.readAll(memberId) | ||
|
||
Then("빈 리스트를 반환 한다") { |
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.
여기 Then 글 잘못된 것 같아요!
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.
고생하셨습니다!
질문 몇 가지 남겼어요~
@Transactional(readOnly = true) | ||
fun readAll(memberId: Long): List<CartProductResponse> { | ||
memberRepository.existByIdOrThrow(memberId, MemberException(NOT_FOUND_MEMBER)) | ||
val cartProducts = cartProductRepository.findAllByMemberId(memberId) | ||
val products = productByIds(cartProducts) | ||
val findAll = productRepository.findAll() | ||
return cartProducts.map { | ||
products[it.id]?.let { product -> CartProductResponse.of(it, product) } | ||
?: CartProductResponse.fromDeletedProduct(it) | ||
} | ||
} |
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.
이 부분도 협의해보고 적용하겠습니다!
val query = jpql { | ||
selectNew<ProductResponse>( | ||
entity(Product::class), | ||
path(Store::name) | ||
).from( | ||
entity(Product::class), | ||
join(Store::class).on(path(Product::storeId).eq(path(Store::id))), | ||
).where( | ||
predicateByIds(ids) | ||
) | ||
} |
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.
멋지게 잘 쓰셨네요!
혹시 데이터 순서도 명시하면 어떨까요?
@@ -177,6 +177,22 @@ class ProductCustomRepositoryImplTest( | |||
} | |||
} | |||
|
|||
Given("다중 id로 ProductResponse를 조회 할 때") { |
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.
👍
When("봉달에 담은 상품이 삭제 되면") { | ||
productRepository.delete(productA) | ||
val response = requestReadAllCartProducts(memberAuthResponse.accessToken) | ||
|
||
Then("삭제된 상품은 구매 불가능 하도록 조회된다") { | ||
val responseBody = response.`as`(Array<CartProductResponse>::class.java) | ||
|
||
assertSoftly(response) { | ||
statusCode shouldBe HttpStatus.OK.value() | ||
responseBody.size shouldBe 3 | ||
responseBody.find { it.productId == productA.id }!!.isOnSale shouldBe false |
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.
업후르브!
).where( | ||
path(CartProduct::memberId).eq(memberId) | ||
) |
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.
o..or..orderBy 해주시면 안될까요..ㅎㅎ
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.
5a50036 최신순으로 반영하였습니다!
storeName = storeName ?: "", | ||
productId = product?.id ?: 0L, | ||
productName = product?.name ?: "", | ||
productThumbnailUrl = product?.thumbnailUrl ?: "", | ||
productPrice = product?.price?.intValueExact() ?: 0, | ||
productDiscountRate = product?.discountRate ?: 0, | ||
productDiscountPrice = product?.discountPrice?.intValueExact() ?: 0, | ||
quantity = cartProduct.quantity.value, | ||
isMale = cartProduct.isMale, | ||
deliveryMethod = cartProduct.deliveryMethod.name, |
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.
null 을 이렇게 사용할 수 있군요!
📌 관련 이슈
📁 작업 설명
봉달에 담겨 있는 상품 조회 API 구현
간접 참조로 되어 있는 product를 조회하기 위해
findAllProductResponseByIdIn()
을 추가 했습니다.테스트 fixture 개선
fixture에서
id = 1L
로 지정하다 보니 생성하고 저장할 때 동일한 객체로 판단해서 update 쿼리가 날아가는 이슈를 겪었습니다.. 수정했어요! 948eaf8기타
- on #37